{"id":205950,"date":"2025-06-12T10:52:15","date_gmt":"2025-06-12T02:52:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205950\/"},"modified":"2025-06-12T10:52:15","modified_gmt":"2025-06-12T02:52:15","slug":"go-rpc-%e5%ba%94%e7%94%a8%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e5%90%88%e7%90%86%e8%a7%84%e5%88%92-protobuf-%e6%96%87%e4%bb%b6%e7%9b%ae%e5%bd%95%e7%bb%93%e6%9e%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205950\/","title":{"rendered":"Go RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f"},"content":{"rendered":"<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728GOLANG\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aGo RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17301668976720407129fda.jpg\" class=\"aligncenter\">,<br \/>\n<strong>RPC \u5e94\u7528\u4e2d Protobuf \u6587\u4ef6\u5408\u7406\u76ee\u5f55\u89c4\u5212<\/strong>,\u5728 Go RPC \u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0c\u5904\u7406 Protobuf (.pb.go) \u6587\u4ef6\u7684\u5b58\u50a8\u4f4d\u7f6e\u548c\u76ee\u5f55\u7ed3\u6784\u81f3\u5173\u91cd\u8981\u3002\u8fd9\u4e9b\u6587\u4ef6\u5728\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u5171\u4eab\uff0c\u56e0\u6b64\u9700\u8981\u7cbe\u5fc3\u5b89\u6392\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002,<br \/>\n<strong>\u76ee\u5f55\u7ed3\u6784\u53c2\u8003<\/strong>,\u4e00\u4e2a\u5408\u7406\u7684\u76ee\u5f55\u7ed3\u6784\u53ef\u4ee5\u5982\u4e0b\uff1a,<br \/>\n<strong>Protobuf \u6587\u4ef6\u4f4d\u7f6e\u7684\u8003\u91cf\u56e0\u7d20<\/strong>,<br \/>\n<strong>\u5efa\u8bae\u7684\u89e3\u51b3\u65b9\u6848<\/strong>,\u5982\u95ee\u9898\u7b54\u6848\u6240\u8ff0\uff0c\u4e00\u4e2a\u597d\u7684\u505a\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7684 Git \u4ed3\u5e93\u6765\u5b58\u50a8 Protobuf \u6587\u4ef6\u3002\u8fd9\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u597d\u5904\uff1a,\u4ee5\u4e0a\u5c31\u662f\u300aGo RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01,<br \/>\n<strong>\u53ef\u7ef4\u62a4\u6027\uff1a<\/strong>\u4ee3\u7801\u7ef4\u62a4\u548c\u91cd\u6784\u5e94\u8be5\u5c3d\u53ef\u80fd\u7b80\u5355\u3002\u5c06 Protobuf \u6587\u4ef6\u7ec4\u7ec7\u5230\u4e00\u4e2a\u903b\u8f91\u7ed3\u6784\u4e2d\u6709\u52a9\u4e8e\u8f7b\u677e\u7ba1\u7406\u548c\u66f4\u65b0\u66f4\u6539\u3002,<br \/>\n<strong>\u53ef\u8bbf\u95ee\u6027\uff1a<\/strong>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u90fd\u9700\u8981\u8bbf\u95ee Protobuf \u6587\u4ef6\u3002\u5c06\u5b83\u4eec\u653e\u5728\u4e00\u4e2a\u4e2d\u592e\u4f4d\u7f6e\u53ef\u786e\u4fdd\u53cc\u65b9\u90fd\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u548c\u66f4\u65b0\u5b83\u4eec\u3002,<br \/>\n<strong>\u91cd\u7528\u6027\uff1a<\/strong>Protobuf \u6587\u4ef6\u7ecf\u5e38\u5728\u591a\u4e2a\u670d\u52a1\u6216\u6a21\u5757\u4e2d\u91cd\u7528\u3002\u5c06\u5176\u96c6\u4e2d\u5b58\u50a8\u5728\u5355\u72ec\u7684\u4ed3\u5e93\u6216\u6a21\u5757\u4e2d\u4fbf\u4e8e\u91cd\u7528\uff0c\u5e76\u6709\u52a9\u4e8e\u4fdd\u6301\u6587\u4ef6\u7684\u7248\u672c\u63a7\u5236\u3002,<\/p>\n<p>github.com\/example\/myapp<\/p>\n<ul>\n<li>\n<p>protos<\/p>\n<ul>\n<li>common (\u5b58\u653e\u901a\u7528\u7684 Protobuf \u6587\u4ef6\uff0c\u5982\u6570\u636e\u7c7b\u578b\u3001\u679a\u4e3e\u548c\u9519\u8bef\u6d88\u606f)<\/li>\n<li>\n<p>services<\/p>\n<ul>\n<li>user (\u9488\u5bf9\u7279\u5b9a\u670d\u52a1\u7684 Protobuf \u6587\u4ef6)<\/li>\n<li>product (\u9488\u5bf9\u7279\u5b9a\u670d\u52a1\u7684 Protobuf \u6587\u4ef6)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>server (\u5b58\u653e\u670d\u52a1\u7aef\u4ee3\u7801)<\/p>\n<ul>\n<li>protos (Protobuf \u6587\u4ef6\u7684\u672c\u5730\u526f\u672c)<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>client (\u5b58\u653e\u5ba2\u6237\u7aef\u4ee3\u7801)<\/p>\n<ul>\n<li>protos (Protobuf \u6587\u4ef6\u7684\u672c\u5730\u526f\u672c)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>,RPC \u5e94\u7528\u4e2d Protobuf \u6587\u4ef6\u5408\u7406\u76ee\u5f55\u89c4\u5212,\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728GOLANG\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aGo RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>Go RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f<\/span><\/p>\n<h1>Go RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f<\/h1>\n<p><span>2024-10-29 09:55:12<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728GOLANG\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aGo RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17301668976720407129fda.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>RPC \u5e94\u7528\u4e2d Protobuf \u6587\u4ef6\u5408\u7406\u76ee\u5f55\u89c4\u5212<\/strong><\/p>\n<p>\u5728 Go RPC \u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0c\u5904\u7406 Protobuf (.pb.go) \u6587\u4ef6\u7684\u5b58\u50a8\u4f4d\u7f6e\u548c\u76ee\u5f55\u7ed3\u6784\u81f3\u5173\u91cd\u8981\u3002\u8fd9\u4e9b\u6587\u4ef6\u5728\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u5171\u4eab\uff0c\u56e0\u6b64\u9700\u8981\u7cbe\u5fc3\u5b89\u6392\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p><strong>\u76ee\u5f55\u7ed3\u6784\u53c2\u8003<\/strong><\/p>\n<p>\u4e00\u4e2a\u5408\u7406\u7684\u76ee\u5f55\u7ed3\u6784\u53ef\u4ee5\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p>github.com\/example\/myapp<\/p>\n<ul>\n<li>\n<p>protos<\/p>\n<ul>\n<li>common (\u5b58\u653e\u901a\u7528\u7684 Protobuf \u6587\u4ef6\uff0c\u5982\u6570\u636e\u7c7b\u578b\u3001\u679a\u4e3e\u548c\u9519\u8bef\u6d88\u606f)<\/li>\n<li>\n<p>services<\/p>\n<ul>\n<li>user (\u9488\u5bf9\u7279\u5b9a\u670d\u52a1\u7684 Protobuf \u6587\u4ef6)<\/li>\n<li>product (\u9488\u5bf9\u7279\u5b9a\u670d\u52a1\u7684 Protobuf \u6587\u4ef6)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>server (\u5b58\u653e\u670d\u52a1\u7aef\u4ee3\u7801)<\/p>\n<ul>\n<li>protos (Protobuf \u6587\u4ef6\u7684\u672c\u5730\u526f\u672c)<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>client (\u5b58\u653e\u5ba2\u6237\u7aef\u4ee3\u7801)<\/p>\n<ul>\n<li>protos (Protobuf \u6587\u4ef6\u7684\u672c\u5730\u526f\u672c)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Protobuf \u6587\u4ef6\u4f4d\u7f6e\u7684\u8003\u91cf\u56e0\u7d20<\/strong><\/p>\n<ul>\n<li><strong>\u91cd\u7528\u6027\uff1a<\/strong>Protobuf \u6587\u4ef6\u7ecf\u5e38\u5728\u591a\u4e2a\u670d\u52a1\u6216\u6a21\u5757\u4e2d\u91cd\u7528\u3002\u5c06\u5176\u96c6\u4e2d\u5b58\u50a8\u5728\u5355\u72ec\u7684\u4ed3\u5e93\u6216\u6a21\u5757\u4e2d\u4fbf\u4e8e\u91cd\u7528\uff0c\u5e76\u6709\u52a9\u4e8e\u4fdd\u6301\u6587\u4ef6\u7684\u7248\u672c\u63a7\u5236\u3002<\/li>\n<li><strong>\u53ef\u8bbf\u95ee\u6027\uff1a<\/strong>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u90fd\u9700\u8981\u8bbf\u95ee Protobuf \u6587\u4ef6\u3002\u5c06\u5b83\u4eec\u653e\u5728\u4e00\u4e2a\u4e2d\u592e\u4f4d\u7f6e\u53ef\u786e\u4fdd\u53cc\u65b9\u90fd\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u548c\u66f4\u65b0\u5b83\u4eec\u3002<\/li>\n<li><strong>\u53ef\u7ef4\u62a4\u6027\uff1a<\/strong>\u4ee3\u7801\u7ef4\u62a4\u548c\u91cd\u6784\u5e94\u8be5\u5c3d\u53ef\u80fd\u7b80\u5355\u3002\u5c06 Protobuf \u6587\u4ef6\u7ec4\u7ec7\u5230\u4e00\u4e2a\u903b\u8f91\u7ed3\u6784\u4e2d\u6709\u52a9\u4e8e\u8f7b\u677e\u7ba1\u7406\u548c\u66f4\u65b0\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p><strong>\u5efa\u8bae\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5982\u95ee\u9898\u7b54\u6848\u6240\u8ff0\uff0c\u4e00\u4e2a\u597d\u7684\u505a\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7684 Git \u4ed3\u5e93\u6765\u5b58\u50a8 Protobuf \u6587\u4ef6\u3002\u8fd9\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u597d\u5904\uff1a<\/p>\n<ul>\n<li><strong>\u4e2d\u592e\u5b58\u50a8\uff1a<\/strong>\u6240\u6709\u9879\u76ee\u90fd\u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u6b64\u5b58\u50a8\u5e93\u6765\u8bbf\u95ee Protobuf \u6587\u4ef6\u3002<\/li>\n<li><strong>\u7248\u672c\u63a7\u5236\uff1a<\/strong>Git \u63d0\u4f9b\u4e86\u5bf9\u6587\u4ef6\u66f4\u6539\u7684\u7248\u672c\u63a7\u5236\uff0c\u7b80\u5316\u4e86\u66f4\u65b0\u548c\u56de\u6eda\u3002<\/li>\n<li><strong>\u72ec\u7acb\u6027\uff1a<\/strong>Protobuf \u6587\u4ef6\u4e0e\u5176\u4ed6\u4ee3\u7801\u57fa\u5206\u79bb\uff0c\u4f7f\u5176\u66f4\u52a0\u6a21\u5757\u5316\u548c\u53ef\u6269\u5c55\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aGo RPC \u5e94\u7528\u4e2d\uff0c\u5982\u4f55\u5408\u7406\u89c4\u5212 Protobuf \u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4f60\u7684\u7535\u8111CPU\u51fa\u73b0\u6545\u969c\uff1f\u5feb\u6765\u4e86\u89e3\u53ef\u80fd\u7684\u6545\u969c\u73b0\u8c61\u548c\u89e3\u51b3\u65b9\u6cd5\uff01\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u82f9\u679c\u624b\u673aUSB\u5171\u4eab\u7f51\u7edc\u7ed9\u7535\u8111\u6ca1\u53cd\u5e94\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728G&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205950","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205950"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205950\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}