{"id":207093,"date":"2025-07-08T11:06:16","date_gmt":"2025-07-08T03:06:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207093\/"},"modified":"2025-07-08T11:06:16","modified_gmt":"2025-07-08T03:06:16","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-go-%e5%92%8c-grpc-%e4%b8%ad%e6%9e%84%e5%bb%ba%e7%bb%93%e6%9e%84%e4%bd%93%e6%95%b0%e7%bb%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207093\/","title":{"rendered":"\u5982\u4f55\u5728 Go \u548c gRPC \u4e2d\u6784\u5efa\u7ed3\u6784\u4f53\u6570\u7ec4\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u5728 Go \u548c gRPC \u4e2d\u6784\u5efa\u7ed3\u6784\u4f53\u6570\u7ec4\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 23:15:21<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5728 Go \u548c gRPC \u4e2d\u6784\u5efa\u7ed3\u6784\u4f53\u6570\u7ec4\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6dfb\u52a0\u5230\u7ed3\u6784\u7684\u5185\u5bb9\u90e8\u5206\u4e2d\uff0c\u5e76\u4ee5 id \u4f5c\u4e3a\u6570\u7ec4\u7d22\u5f15\u3002\u6211\u7684\u4ee3\u7801\u9002\u7528\u4e8e\u4e00\u4e2a\u5143\u7d20\uff0c\u4f46\u5f53\u6211\u5c1d\u8bd5\u6dfb\u52a0\u5faa\u73af\u65f6\u51fa\u73b0\u5404\u79cd\u9519\u8bef\u3002\u6b22\u8fce\u4efb\u4f55\u60f3\u6cd5\u3002\u6211\u6b63\u5728\u4f7f\u7528 go\u3002<\/p>\n<pre>func buildRequest(s []string) []*storepb.LongStoreRequest { \n\/\/      ss:= []storepb.LongStoreRequest \n\/\/ int32 i =0 stringv := s[0] \n\/\/      for i := 0; i &lt; len(s); i++ {\n    \/\/              println(i, apps[i])\n    ss := []*storepb.LongStoreRequest{\n            &amp;storepb.LongStoreRequest {\n                    Msg: &amp;storepb.StoreMessage{\n                            Content: stringv,\n                            Account:  \"trevor3\",\n                            Parent: \"parentrec\",\n                            Id: 0,\n                    },\n                    }, \n            } \/\/      }\n        return ss \n}<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u5982\u679c\u6211\u6b63\u786e\u7406\u89e3\u4f60\u7684\u63cf\u8ff0\uff0c\u4f60\u60f3\u8981\u6784\u5efa\u4e00\u4e2a longstorerequests \u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5bf9\u5e94\u4e8e\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u9879\u76ee\uff0c id \u7ed9\u51fa\u6570\u7ec4\u7d22\u5f15\u3002\u5982\u679c\u8fd9\u786e\u5b9e\u662f\u60a8\u6240\u9700\u8981\u7684\uff0c\u90a3\u4e48\u7c7b\u4f3c\u8fd9\u6837\u7684\u4e8b\u60c5\u5e94\u8be5\u6709\u6548\uff1a<\/p>\n<pre>ss := []*storepb.LongStoreRequest{}\nfor i,str:=range s {\n  ss=append(ss,&amp;storepb.LongStoreRequest {\n                  Msg: &amp;storepb.StoreMessage{\n                            Content: str,\n                            Account:  \"trevor3\",\n                            Parent: \"parentrec\",\n                            Id: i,\n                    }})\n}<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u5982\u4f55\u5728 Go \u548c gRPC \u4e2d\u6784\u5efa\u7ed3\u6784\u4f53\u6570\u7ec4\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#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-207093","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207093","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=207093"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207093\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}