{"id":10006925,"date":"2022-11-28T16:48:07","date_gmt":"2022-11-28T08:48:07","guid":{"rendered":"https:\/\/ityet.com\/?p=10006925"},"modified":"2022-11-28T16:48:07","modified_gmt":"2022-11-28T08:48:07","slug":"%e3%80%90go%e5%be%ae%e6%9c%8d%e5%8a%a1%e3%80%91%e5%bc%80%e5%8f%91grpc%e6%80%bb%e5%85%b1%e5%88%86%e4%b8%89%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006925","title":{"rendered":"\u3010Go\u5fae\u670d\u52a1\u3011\u5f00\u53d1gRPC\u603b\u5171\u5206\u4e09\u6b65"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u6211\u4eec\u4ecb\u7ecd\u4e86ProtoBuf\u7684\u4f7f\u7528\uff0c\u4e0d\u4e86\u89e3ProtoBuf\u7684\u540c\u5b66\u5efa\u8bae\u5148\u8bfb\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/segmentfault.com\/a\/1190000042764979\"># \u4e00\u6587\u5e26\u4f60\u73a9\u8f6cProtoBuf<\/a>\uff0c\u4f1a\u7528protobuf\u662f\u5b66\u4e60gRPC\u7684\u57fa\u7840\u3002<\/p>\n<p>\u4e4b\u524d\u6211\u4e5f\u6709\u5199\u8fc7RPC\u76f8\u5173\u7684\u6587\u7ae0\uff1a\u300a Go RPC\u5165\u95e8\u6307\u5357\uff1aRPC\u7684\u4f7f\u7528\u8fb9\u754c\u5728\u54ea\u91cc\uff1f\u5982\u4f55\u5b9e\u73b0\u8de8\u8bed\u8a00\u8c03\u7528\uff1f\u300b\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e86RPC\u662f\u4ec0\u4e48\uff0c\u4f7f\u7528\u8fb9\u754c\u5728\u54ea\u91cc\uff1f\u5e76\u4e14\u7528Go\u548cphp\u4e3e\u4f8b\uff0c\u5b9e\u73b0\u4e86\u8de8\u8bed\u8a00\u8c03\u7528\u3002\u4e0d\u4e86\u89e3RPC\u7684\u540c\u5b66\u5efa\u8bae\u5148\u8bfb\u8fd9\u7bc7\u6587\u7ae0\u8865\u8865\u8bfe\u3002<\/p>\n<p>\u4e0a\u9762\u63d0\u5230\u7684\u8fd9\u4e9b\u57fa\u7840\u77e5\u8bc6\uff0c\u4e0d\u4f5c\u4e3a\u672c\u6587\u7684\u91cd\u70b9\u3002<\/p>\n<p><strong>\u8fd9\u7bc7\u6587\u7ae0\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5728\u5fae\u670d\u52a1\u4e2dgRPC\u7684\u4f7f\u7528\uff1a<\/strong><\/p>\n<h2>\u5f00\u53d1\u6d41\u7a0b<\/h2>\n<p>\u5728\u5fae\u670d\u52a1\u5206\u5e03\u5f0f\u67b6\u6784\u4e2d\u5f00\u53d1gRPC\u5176\u5b9e\u975e\u5e38\u7b80\u5355\uff0c\u4e0d\u8981\u754f\u96be\u754f\u70e6\uff0c\u6ca1\u6709\u4ec0\u4e48\u5fc3\u667a\u8d1f\u62c5\u7684\u3002<\/p>\n<p>\u5f00\u53d1gRPC\u7684\u6d41\u7a0b\u548c\u5b8b\u4e39\u4e39\u628a\u5927\u8c61\u88c5\u51b0\u7bb1\u662f\u4e00\u6837\u7684\uff1a<\/p>\n<ol>\n<li>\u628a\u51b0\u7bb1\u95e8\u6253\u5f00<\/li>\n<li>\u628a\u5927\u8c61\u88c5\u8fdb\u53bb<\/li>\n<li>\u628a\u51b0\u7bb1\u95e8\u5173\u4e0a<\/li>\n<\/ol>\n<p>\u5f00\u53d1gRPC\u7684\u6d41\u7a0b\uff1b<\/p>\n<ol>\n<li>\u5199proto\u6587\u4ef6\u5b9a\u4e49\u670d\u52a1\u548c\u6d88\u606f<\/li>\n<li>\u4f7f\u7528protoc\u5de5\u5177\u751f\u6210\u4ee3\u7801<\/li>\n<li>\u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u63d0\u4f9b\u670d\u52a1<\/li>\n<\/ol>\n<p>\u5c31\u662f\u8fd9\u4e48\u7b80\u5355\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4ecd\u7136\u4ee5Go\u8bed\u8a00\u4e3e\u4f8b\uff0c\u5176\u4ed6\u8bed\u8a00\u7684\u5b9e\u73b0\u601d\u8def\u4e5f\u662f\u4e00\u6837\u7684\u3002<\/p>\n<h2>\u5165\u95e8\u5b9e\u8df5<\/h2>\n<p>\u4e3a\u4e86\u8ba9\u5927\u5bb6\u66f4\u597d\u7406\u89e3\uff0c\u6211\u53c2\u8003gRPC\u5b98\u65b9\u6587\u6863\uff0c\u5199\u4e86\u4e00\u4e2ahelloword\u793a\u4f8b\u3002<\/p>\n<p>\u4e0b\u56fe\u662f\u4f7f\u7528Go\u5b9e\u73b0gRPC\u5f00\u53d1\u7684\u76ee\u5f55\u7ed3\u6784\u56fe\uff0c\u5148\u8ba9\u5927\u5bb6\u6709\u4e2a\u6574\u4f53\u7684\u8ba4\u8bc6\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835134\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6b22\u8fce\u5927\u5bb6\u6309\u7167\u6211\u7684\u6b65\u9aa4\u8fdb\u884c\u590d\u523b\u5b9e\u8df5\uff1a<\/p>\n<p><strong>\u770b\u6587\u7ae0\u662f\u5b66\u4e0d\u4f1a\u7f16\u7a0b\u7684\uff0c\u4f46\u662f\u4e00\u8fb9\u770b\u6587\u7ae0\u4e00\u8fb9\u6572\u4ee3\u7801\u53ef\u4ee5\uff01<\/strong><\/p>\n<h3>1. \u5199proto\u6587\u4ef6\u5b9a\u4e49\u670d\u52a1\u548c\u6d88\u606f<\/h3>\n<p><em>service Greeter {}<\/em> \u662f\u6211\u4eec\u5b9a\u4e49\u7684\u670d\u52a1<\/p>\n<p><em>rpc SayHello (HelloRequest) returns (HelloReply) {}<\/em> \u662f\u5728\u670d\u52a1\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5<\/p>\n<p><em>protoc\u5de5\u5177\u96c6<\/em>\uff0c\u4f1a\u6839\u636e\u6211\u4eec\u5b9a\u4e49\u7684\u670d\u52a1\u3001\u65b9\u6cd5\u3001\u548c\u6d88\u606f\u751f\u6210\u6307\u5b9a\u8bed\u8a00\u7684\u4ee3\u7801\u3002<\/p>\n<pre><code class=\"Go\">syntax = &quot;proto3&quot;;\n\noption go_package = &quot;.\/;hello&quot;;\n\npackage hello;\n\nservice Greeter {\nrpc SayHello (HelloRequest) returns (HelloReply) {}\n}\n\nmessage HelloRequest {\nstring name = 1;\n}\n\nmessage HelloReply {\nstring message = 1;\n}<\/code><\/pre>\n<p>\u5982\u679c\u5c0f\u4f19\u4f34\u4eec\u770b\u4e0a\u9762\u4ee3\u7801\u6709\u4e0d\u61c2\u7684\u5730\u65b9\uff0c\u90a3\u5c31\u662fprotobuf\u57fa\u7840\u4e0d\u7262\u4e86\uff0c\u8bf7\u770b\u8fd9\u7bc7\uff1a<a href=\"https:\/\/segmentfault.com\/a\/1190000042764979\">\u4e00\u6587\u5e26\u4f60\u73a9\u8f6cprotobuf<\/a>\uff0c\u56de\u987e\u4e00\u4e0b\u77e5\u8bc6\u70b9\u3002<\/p>\n<h3>2. \u4f7f\u7528protoc\u5de5\u5177\u751f\u6210\u4ee3\u7801<\/h3>\n<p>\u5207\u6362\u5230proto\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u4e0b<\/p>\n<pre><code>cd protos\/helloword\/<\/code><\/pre>\n<p>\u751f\u6210Go\u4ee3\u7801<\/p>\n<pre><code>protoc --go_out=. helloworld.proto<\/code><\/pre>\n<blockquote><p>\u5c0f\u6280\u5de7\u4e4b<em>\u540c\u6b65\u4f9d\u8d56<\/em>\uff1a\u5f53\u4f60\u751f\u6210Go\u4ee3\u7801\u540e\uff0c\u53d1\u73b0\u751f\u6210\u7684\u6587\u4ef6\u98d8\u7ea2\u62a5\u9519\uff0c\u4e0d\u8981\u7d27\u5f20\uff0c\u591a\u6570\u60c5\u51b5\u662f\u56e0\u4e3a\u4f9d\u8d56\u4e0d\u5b58\u5728\u5bfc\u81f4\u7684\u3002<\/p><\/blockquote>\n<p>\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u540c\u6b65\u4f9d\u8d56\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n<pre><code>go mod tidy<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835135\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>3. \u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801 \u63d0\u4f9b\u670d\u52a1<\/h3>\n<p>\u4e0b\u9762\u662f\u4eca\u5929\u7684\u91cd\u70b9\uff0c\u6211\u4eec\u7528Go\u5b9e\u73b0\u4e1a\u52a1\u903b\u8f91\u7684\u7f16\u5199\uff0c\u6ce8\u610f\u770b\uff1a<\/p>\n<p><strong>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u5f00\u53d1gRPC\u65f6\uff0c\u4e00\u5b9a\u6709\u4e24\u4e2a\u7aef\uff1a\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u3002<\/strong><\/p>\n<p>\u6211\u4eec\u7684\u4e60\u60ef\u662f\uff0c\u5728\u641e\u5b9aprotobuf\u4e4b\u540e\uff0c\u5148\u5199\u670d\u52a1\u7aef\u903b\u8f91\uff0c\u66b4\u9732\u7aef\u53e3\uff0c\u63d0\u4f9b\u670d\u52a1\uff1b\u518d\u5199\u5ba2\u6237\u7aef\u903b\u8f91\uff0c\u8fde\u63a5\u670d\u52a1\uff0c\u53d1\u9001\u8bf7\u6c42\uff0c\u5904\u7406\u54cd\u5e94\u3002<\/p>\n<blockquote><p>\u5c0f\u63d0\u793a\uff1aPHP\u548cObjective-C\u53ea\u80fd\u5b9e\u73b0gRPC\u4e2d\u7684\u5ba2\u6237\u7aef\uff0c\u4e0d\u80fd\u5b9e\u73b0\u670d\u52a1\u7aef\u3002<\/p><\/blockquote>\n<h4>3.1 \u7f16\u5199\u670d\u52a1\u7aef\u4e1a\u52a1\u903b\u8f91<\/h4>\n<p>\u7f16\u5199\u670d\u52a1\u7aef\u975e\u5e38\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5b9e\u73b0\u5728proto\u4e2d\u5b9a\u4e49\u7684rpc\u65b9\u6cd5\u3002<\/p>\n<blockquote><p>\u5c0f\u6280\u5de7\uff1a\u5728\u6211\u4eec\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165protos\u670d\u52a1\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u662f\u4e00\u4e2a\u6bd4\u8f83\u957f\u7684\u540d\u5b57\uff0c\u5efa\u8bae\u7ed3\u5408\u81ea\u5df1\u9879\u76ee\uff0c\u6539\u6210\u6bd4\u8f83\u77ed\u53c8\u5bb9\u6613\u7406\u89e3\u7684\u540d\u5b57\u3002<\/p><\/blockquote>\n<pre><code class=\"go\">package greeter_server\n\nimport &quot;context&quot;\n\n\/\/\u5bfc\u5165\u6211\u4eec\u5728protos\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u670d\u52a1\nimport pb &quot;sifou\/rpc\/protos\/helloworld&quot;\n\n\/\/\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u4f5c\u7528\u662f\u5b9e\u73b0helloworld\u4e2d\u7684GreeterServer\ntype server struct{}\n\n\/\/ SayHello implements helloworld.GreeterServer\nfunc (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {\n   return &amp;pb.HelloReply{Message: &quot;Hello &quot; + in.Name}, nil\n}<\/code><\/pre>\n<p>\u4ee5\u4e0a\u5c31\u5b8c\u6210\u4e86\u670d\u52a1\u7aef\u7684\u4e1a\u52a1\u903b\u8f91\u7f16\u5199\uff1a<\/p>\n<ol>\n<li>\u7528\u6211\u4eec\u5728proto\u4e2d\u5b9a\u4e49\u7684\u6d88\u606f\uff0c\u6784\u5efa\u5e76\u586b\u5145\u4e86\u4e00\u4e2a\u6211\u4eec\u5728\u63a5\u53e3\u5b9a\u4e49\u7684 <code>HelloReply<\/code> \u5e94\u7b54\u5bf9\u8c61\u3002<\/li>\n<li>\u5c06 <code>HelloReply<\/code> \u5bf9\u8c61\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ol>\n<p>\u5230\u8fd9\u91cc\u4e1a\u52a1\u529f\u80fd\u662f\u5b9e\u73b0\u4e86\uff0c\u4f46\u662f\u670d\u52a1\u7aef\u7684\u4e1a\u52a1\u5982\u4f55\u8ba9\u5ba2\u6237\u7aef\u8c03\u7528\u5462\uff1f<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u7ee7\u7eed\u7f16\u5199\uff1a\u66b4\u9732\u7aef\u53e3\uff0c\u63d0\u4f9b\u670d\u52a1<\/p>\n<h4>3.2 \u66b4\u9732\u7aef\u53e3\uff0c\u63d0\u4f9b\u670d\u52a1<\/h4>\n<blockquote><p>\u8e29\u5751\u5206\u4eab\uff1a\u6211\u5728\u7f16\u7801\u7684\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u4e86\u9519\u8bef\u7684gRPC\u4f9d\u8d56\uff0c\u6d6a\u8d39\u4e86\u4e0d\u5c11\u65f6\u95f4\u3002\u5e94\u8be5\u7528\u4e0b\u9762\u8fd9\u4e2a\u4f9d\u8d56\u5305\uff1a<\/p><\/blockquote>\n<pre><code class=\"go\">go get google.golang.org\/grpc<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u5728 3.1\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u7684\uff0c\u5e76\u4e0d\u662f\u53e6\u5916\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Go\u6587\u4ef6\u3002<\/strong><\/p>\n<p>\u5173\u952e\u4ee3\u7801\u6ce8\u91ca\u5df2\u7ecf\u5728\u4ee3\u7801\u6bb5\u4e2d\u5199\u6e05\u695a\u4e86\uff0c\u5efa\u8bae\u5927\u5bb6\u53c2\u8003\u6b65\u9aa4\uff0c\u624b\u6572\u4e00\u904d\u3002<\/p>\n<pre><code class=\"go\">package main\n\nimport (\n   &quot;context&quot;\n   &quot;flag&quot;\n   &quot;fmt&quot;\n   &quot;google.golang.org\/gRPC&quot;\n   &quot;log&quot;\n   &quot;net&quot;\n)\n\n\/\/\u5bfc\u5165\u6211\u4eec\u5728protos\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u670d\u52a1\nimport pb &quot;sifou\/rpc\/protos\/helloworld&quot;\n\n\/\/\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u4f5c\u7528\u662f\u5b9e\u73b0helloworld\u4e2d\u7684GreeterServer\ntype server struct {\n   pb.UnimplementedGreeterServer\n}\n\n\/\/ SayHello implements helloworld.GreeterServer\nfunc (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {\n   return &amp;pb.HelloReply{Message: &quot;Hello &quot; + in.Name}, nil\n}\n\n\/\/\u5b9a\u4e49\u7aef\u53e3\u53f7 \u652f\u6301\u542f\u52a8\u7684\u65f6\u5019\u8f93\u5165\u7aef\u53e3\u53f7\nvar (\n   port = flag.Int(&quot;port&quot;, 50051, &quot;The server port&quot;)\n)\n\nfunc main() {\n   \/\/\u89e3\u6790\u8f93\u5165\u7684\u7aef\u53e3\u53f7 \u9ed8\u8ba450051\n   flag.Parse()\n   \/\/tcp\u534f\u8bae\u76d1\u542c\u6307\u5b9a\u7aef\u53e3\u53f7\n   lis, err := net.Listen(&quot;tcp&quot;, fmt.Sprintf(&quot;:%d&quot;, *port))\n   if err != nil {\n      log.Fatalf(&quot;failed to listen: %v&quot;, err)\n   }\n   \/\/\u5b9e\u4f8b\u5316gRPC\u670d\u52a1\n   s := gRPC.NewServer()\n   \/\/\u670d\u52a1\u6ce8\u518c\n   pb.RegisterGreeterServer(s, &amp;server{})\n   log.Printf(&quot;server listening at %v&quot;, lis.Addr())\n   \/\/\u542f\u52a8\u670d\u52a1\n   if err := s.Serve(lis); err != nil {\n      log.Fatalf(&quot;failed to serve: %v&quot;, err)\n   }\n}<\/code><\/pre>\n<p>\u542f\u52a8\u6210\u529f\uff0c\u666e\u5929\u540c\u5e86\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835136\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>\u5230\u8fd9\u91cc\u6211\u4eec\u5c31\u5b8c\u6210\u4e86gRPC\u670d\u52a1\u7aef\u7684\u7f16\u5199\uff1a\u6211\u4eec\u5b9e\u73b0\u4e86\u5c06 <code>Greeter<\/code> \u670d\u52a1\u7ed1\u5b9a\u5230\u4e00\u4e2a\u7aef\u53e3\uff0c\u6211\u4eec\u542f\u52a8\u8fd9\u4e2a\u670d\u52a1\u65f6\uff0c\u670d\u52a1\u7aef\u5df2\u51c6\u5907\u597d\u4ece <code>Greeter<\/code> \u670d\u52a1\u7684\u5ba2\u6237\u7aef\u63a5\u6536\u8bf7\u6c42\u4e86\u3002<\/strong><\/p>\n<p>\u6211\u4eec\u63a5\u4e0b\u6765\u518d\u7f16\u5199\u5ba2\u6237\u7aef\uff1a<\/p>\n<h4>3.3 \u7f16\u5199\u5ba2\u6237\u7aef\u903b\u8f91\u4ee3\u7801<\/h4>\n<p>\u5ba2\u6237\u7aef\u7684 gRPC \u66f4\u7b80\u5355\uff01<\/p>\n<p>\u6211\u4eec\u5c06\u7528protoc\u751f\u6210\u7684\u4ee3\u7801\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u6765\u8bbf\u95ee\u6211\u4eec\u5728\u521b\u5efa\u7684 <code>Greeter<\/code> \u670d\u52a1\u7aef\u3002<\/p>\n<blockquote><p>\u5c0f\u6280\u5de7\uff1a\u5728 gRPC Go \u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7279\u6b8a\u7684 Dial() \u65b9\u6cd5\u6765\u521b\u5efa\u9891\u9053\uff0c\u5b9e\u73b0\u548c\u670d\u52a1\u7aef\u7684\u8fde\u63a5\u3002<\/p><\/blockquote>\n<p>\u5173\u952e\u4ee3\u7801\u5df2\u6dfb\u52a0\u6ce8\u91ca\uff0c\u7f16\u5199\u5ba2\u6237\u7aef\u903b\u8f91\u4ee3\u7801\uff0c\u5f3a\u70c8\u5efa\u8bae\u5927\u5bb6\u548c\u6211\u4e00\u8d77\u624b\u6572\u4e00\u904d\u3002<\/p>\n<p><strong>\u201c\u7f16\u7a0b\u8981\u6709\u5de5\u5320\u7cbe\u795e\uff0c\u505a\u7684\u591a\u4e86\u624b\u611f\u5c31\u51fa\u6765\u4e86\u3002\u201d<\/strong><\/p>\n<pre><code class=\"go\">package main\n\nimport (\n   &quot;context&quot;\n   &quot;flag&quot;\n   &quot;google.golang.org\/gRPC&quot; \/\/\u8fd9\u4e2a\u4f9d\u8d56\u4e0d\u8981\u641e\u9519\n   &quot;google.golang.org\/gRPC\/credentials\/insecure&quot;\n   pb &quot;sifou\/rpc\/protos\/helloworld&quot;\n   &quot;log&quot;\n   &quot;time&quot;\n)\n\n\/\/\u9ed8\u8ba4\u6570\u636e \u4e5f\u652f\u6301\u5728\u63a7\u5236\u53f0\u81ea\u5b9a\u4e49\nconst (\n   defaultName = &quot;world&quot;\n)\n\n\/\/\u76d1\u542c\u5730\u5740\u548c\u4f20\u5165\u7684name\nvar (\n   addr = flag.String(&quot;addr&quot;, &quot;localhost:50051&quot;, &quot;the address to connect to&quot;)\n   name = flag.String(&quot;name&quot;, defaultName, &quot;Name to greet&quot;)\n)\n\nfunc main() {\n   flag.Parse()\n   \/\/\u901a\u8fc7gRPC.Dial()\u65b9\u6cd5\u5efa\u7acb\u670d\u52a1\u8fde\u63a5\n   conn, err := gRPC.Dial(*addr, gRPC.WithTransportCredentials(insecure.NewCredentials()))\n   if err != nil {\n      log.Fatalf(&quot;did not connect: %v&quot;, err)\n   }\n   \/\/\u8fde\u63a5\u8981\u8bb0\u5f97\u5173\u95ed\n   defer func(conn *gRPC.ClientConn) {\n      err := conn.Close()\n      if err != nil {\n\n      }\n   }(conn)\n   \/\/\u5b9e\u4f8b\u5316\u5ba2\u6237\u7aef\u8fde\u63a5\n   c := pb.NewGreeterClient(conn)\n\n   \/\/\u8bbe\u7f6e\u8bf7\u6c42\u4e0a\u4e0b\u6587\uff0c\u56e0\u4e3a\u662f\u7f51\u7edc\u8bf7\u6c42\uff0c\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\n   ctx, cancel := context.WithTimeout(context.Background(), time.Second)\n   defer cancel()\n   \/\/\u5ba2\u6237\u7aef\u8c03\u7528\u5728proto\u4e2d\u5b9a\u4e49\u7684SayHello()rpc\u65b9\u6cd5\uff0c\u53d1\u8d77\u8bf7\u6c42\uff0c\u63a5\u6536\u670d\u52a1\u7aef\u54cd\u5e94\n   r, err := c.SayHello(ctx, &amp;pb.HelloRequest{Name: *name})\n   if err != nil {\n      log.Fatalf(&quot;could not greet: %v&quot;, err)\n   }\n   log.Printf(&quot;Greeting: %s&quot;, r.GetMessage())\n}<\/code><\/pre>\n<p>\u5230\u8fd9\u91cc\u6211\u4eec\u5c31\u5df2\u7ecf\u5b8c\u6210\u4e86\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u4e1a\u52a1\u903b\u8f91\u7684\u7f16\u5199\uff0c\u4e0b\u9762\u5c31\u662f\u89c1\u8bc1\u5947\u8ff9\u7684\u65f6\u523b\u4e86\uff1a<\/p>\n<h4>3.4 \u8c03\u7528gRPC \u4e24\u7aef\u4e92\u901a<\/h4>\n<p>\u5982\u4f55\u5b9e\u73b0\u4e24\u7aef\u7684\u6d88\u606f\u4e92\u901a\uff1f<\/p>\n<ol>\n<li>\u6211\u4eec\u4e4b\u524d\u5df2\u7ecf\u6253\u5f00\u4e86\u4e00\u4e2a\u7ec8\u7aef\uff0c\u542f\u52a8\u4e86\u670d\u52a1\u7aef\u7684\u670d\u52a1\u3002<\/li>\n<li>\u6211\u4eec\u518d\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u7ec8\u7aef\uff0c\u8fd0\u884c\u5ba2\u6237\u7aef\uff0c\u770b\u4e0b\u670d\u52a1\u7aef\u662f\u5426\u7ed9\u6211\u4eec\u8fd4\u56de\u4e86\u6570\u636e\uff1a<\/li>\n<\/ol>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835137\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u548c\u6211\u4eec\u9884\u60f3\u4e2d\u7684\u7ed3\u679c\u4e00\u6837\uff1a<\/p>\n<p><strong>\u670d\u52a1\u7aef\u7ed9\u6211\u4eec\u8fd4\u56de\u4e86\u201cHello world\u201d\uff0c\u5176\u4e2dHello\u662f\u670d\u52a1\u7aef\u8bbe\u7f6e\u7684\uff0cworld\u662f\u5ba2\u6237\u7aef\u4f20\u7ed9\u670d\u52a1\u7aef\u7684\u53c2\u6570\uff0c\u670d\u52a1\u7aef\u8fdb\u884c\u62fc\u63a5\u4e4b\u540e\u7ed9\u5ba2\u6237\u7aef\u8fd4\u56de\u4e86\u3002<\/strong><\/p>\n<p>\u81f3\u6b64\uff0c\u4e00\u4e2a\u7ecf\u5178\u7684gRPC\u901a\u4fe1\u793a\u4f8b\u5c31\u641e\u5b9a\u4e86\uff01<\/p>\n<h4>\u6269\u5c55\uff1a\u81ea\u5b9a\u4e49\u8f93\u5165<\/h4>\n<p>\u6ca1\u7528\u8fc7go flag\u81ea\u5b9a\u4e49\u8f93\u5165\u7684\u5c0f\u4f19\u4f34\u91cd\u70b9\u770b\u4e00\u4e0b\uff0c\u8fd9\u90e8\u5206\u662f\u4e3a\u4f60\u5199\u7684\uff1a<\/p>\n<p>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u4ee3\u7801\u4e2d\u7684<strong>flag.Parse<\/strong>\u7684\u4f5c\u7528\u662f\uff1a\u652f\u6301\u6211\u4eec\u5728\u7ec8\u7aef\u63a7\u5236\u53f0\u81ea\u5b9a\u4e49\u8f93\u5165\u53c2\u6570\uff0c\u5982\u679c\u6ca1\u6709\u8f93\u5165\u7684\u8bdd\uff0c\u4f7f\u7528\u7a0b\u5e8f\u4e2d\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u53c2\u6570\uff0c\u6bd4\u5982\u5ba2\u6237\u7aef\u7684name\uff0c\u5728\u4ee3\u7801\u4e2d\u662f\u8fd9\u4e48\u5b9a\u4e49\u7684\uff1a<\/p>\n<pre><code class=\"go\">name = flag.String(&quot;name&quot;, &quot;world&quot;, &quot;Name to greet&quot;)<\/code><\/pre>\n<p>\u6211\u4eec\u5728\u7ec8\u7aef\u8f93\u5165\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"shell\">go run main.go --name \u738b\u4e2d\u9633<\/code><\/pre>\n<p>\u6548\u679c\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835138\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u597d\u4e86\uff0c\u54b1\u4eec\u518d\u63a5\u7740\u804a\u8fdb\u9636\u7684\u5185\u5bb9\uff1a<\/p>\n<p>gRPC\u53e6\u5916\u4e00\u4e2a\u7279\u70b9\u5c31\u662f\u548c\u8bed\u8a00\u65e0\u5173\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u8bed\u8a00\u5b9a\u4e49\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u3002<\/p>\n<p>\u4e0b\u9762\u54b1\u4eec\u518d\u8fdb\u9636\u5b9e\u6218\u4e00\u4e0b\uff0c\u7528gRPC\u5b9e\u73b0\u8de8\u8bed\u8a00\u7684\u8c03\u7528\u3002<\/p>\n<h2>\u8fdb\u9636\u5b9e\u6218\uff1a\u8de8\u8bed\u8a00\u8c03\u7528<\/h2>\n<p>\u5165\u95e8\u5b9e\u6218\u6211\u7ed9\u51fa\u4e86\u8be6\u7ec6\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u751a\u81f3\u8fde\u76ee\u5f55\u7ed3\u6784\u90fd\u5206\u4eab\u7ed9\u5927\u5bb6\u4e86\uff0c\u76f8\u4fe1\u5927\u5bb6\u53ea\u8981\u6309\u7167\u6b65\u9aa4\u590d\u523b\uff0c\u4e00\u5b9a\u4e5f\u80fd\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<p>\u5173\u4e8e\u8fdb\u9636\u5b9e\u6218\u7684\u8de8\u8bed\u8a00\u8c03\u7528\uff1a\u670d\u52a1\u7aef\u4e0d\u91cd\u590d\u7f16\u5199\u4e86\uff0c<em>\u6211\u4eec\u4ecd\u7136\u4f7f\u7528\u4e0a\u9762\u7528Go\u7f16\u5199\u7684\u670d\u52a1\u7aef\u3002<\/em><\/p>\n<p>\u5ba2\u6237\u7aef\u6211\u5c06\u7528\u6211\u719f\u6089\u7684PHP\u8bed\u8a00\u6765\u7f16\u5199\uff0c\u5b9e\u73b0\u4e24\u7aef\u7684rpc\u901a\u4fe1\u3002<\/p>\n<p><strong>\u5efa\u8bae\u5927\u5bb6\u56de\u987e\u4e00\u4e0b\u201c\u5927\u8c61\u88c5\u51b0\u7bb1\u201d\u7684\u6b65\u9aa4\uff0c\u7528\u81ea\u5df1\u64c5\u957f\u7684\u8bed\u8a00\u5f00\u53d1\u5ba2\u6237\u7aef\uff0c\u50cf\u6211\u4e00\u6837\u5b9e\u73b0gRPC\u7684\u8de8\u8bed\u8a00\u8c03\u7528\u3002<\/strong><\/p>\n<h3>1. \u7f16\u5199proto\u6587\u4ef6<\/h3>\n<p>\u548c\u5165\u95e8\u5b9e\u6218\u662f\u4e00\u6837\u7684<\/p>\n<h3>2. \u6839\u636eproto\u6587\u4ef6\u751f\u6210\u4ee3\u7801<\/h3>\n<p>\u548c\u5165\u95e8\u5b9e\u6218\u601d\u8def\u4e00\u6837\uff0c\u533a\u522b\u6307\u5b9a\u751f\u6210\u4ee3\u7801\u8bed\u8a00\u4e0d\u4e00\u6837\uff1a<\/p>\n<pre><code class=\"php\">protoc-gen-php -i . -o . .\/helloworld.proto<\/code><\/pre>\n<h3>3. \u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801<\/h3>\n<h4>3.1 \u5148\u5199\u670d\u52a1\u7aef<\/h4>\n<p>\u670d\u52a1\u7aef\u4f7f\u7528Go\u5b9e\u73b0\u7684\u670d\u52a1\u7aef\uff0c\u4e0d\u8fdb\u884c\u7f16\u5199\u3002<\/p>\n<p>\u786e\u5b9a\u670d\u52a1\u7aef\u662f\u5f00\u542f\u72b6\u6001\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835139\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u518d\u6b21\u63d0\u9192\u4e00\u4e0b\uff1a<\/p>\n<blockquote><p>PHP\u548cObjective-C\u53ea\u80fd\u5b9e\u73b0gRPC\u4e2d\u7684\u5ba2\u6237\u7aef\uff0c\u4e0d\u80fd\u5b9e\u73b0\u670d\u52a1\u7aef\u3002<\/p><\/blockquote>\n<h4>3.2 \u518d\u5199\u5ba2\u6237\u7aef<\/h4>\n<p>\u6211\u7528PHP\u5b9e\u73b0\u5ba2\u6237\u7aef\u7684\u7f16\u5199\uff0c\u4f60\u64c5\u957f\u4ec0\u4e48\u8bed\u8a00\u5462\uff1f\u6709\u6ca1\u6709\u8e29\u5230\u5751\uff0c\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u533a\u8ba8\u8bba\u3002<\/p>\n<pre><code class=\"php\">&lt;?php\n\/\/\u547d\u540d\u7a7a\u95f4\nnamespace Helloworld;\n\n\/\/\u5b9a\u4e49PHP\u5ba2\u6237\u7aef\nclass GreeterClient extends \/gRPC\/BaseStub\n{\n\n  \/\/\u5b9a\u4e49\u6784\u9020\u65b9\u6cd5\n  public function __construct($hostname, $opts, $channel = null)\n  {\n    parent::__construct($hostname, $opts, $channel);\n  }\n\n  \/**\n   * \u5b9e\u73b0proto\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684SayHello()\u65b9\u6cd5\n   * Sends a greeting\n   * @param \/Helloworld\/HelloRequest $argument input argument\n   * @param array $metadata metadata\n   * @param array $options call options\n   * @return \/gRPC\/UnaryCall\n   *\/\n  public function SayHello(\/Helloworld\/HelloRequest $argument,\n                           $metadata = [], $options = [])\n  {\n    return $this-&gt;_simpleRequest('\/helloworld.Greeter\/SayHello',\n      $argument,\n      ['\/Helloworld\/HelloReply', 'decode'],\n      $metadata, $options);\n  }\n\n}<\/code><\/pre>\n<h4>3.3 \u542f\u52a8\u670d\u52a1\uff0c\u8fdb\u884c\u8c03\u7528<\/h4>\n<p>\u7f16\u5199PHP\u811a\u672c\u6587\u4ef6\uff1a<\/p>\n<p>\u8fde\u63a5<code>50051<\/code>\u7aef\u53e3\uff08Go\u5b9e\u73b0\u7684gRPC\u670d\u52a1\u7aef\u5bf9\u5916\u66b4\u9732\u7684\u7aef\u53e3\uff09<\/p>\n<pre><code class=\"php\">&lt;?php\nrequire dirname(__FILE__).'\/vendor\/autoload.php';\n\nfunction greet($hostname, $name)\n{\n    $client = new Helloworld\/GreeterClient($hostname, [\n        'credentials' =&gt; gRPC\/ChannelCredentials::createInsecure(),\n    ]);\n    $request = new Helloworld\/HelloRequest();\n    $request-&gt;setName($name);\n    list($response, $status) = $client-&gt;SayHello($request)-&gt;wait();\n    if ($status-&gt;code !== gRPC\/STATUS_OK) {\n        echo &quot;ERROR: &quot; . $status-&gt;code . &quot;, &quot; . $status-&gt;details . PHP_EOL;\n        exit(1);\n    }\n    echo $response-&gt;getMessage() . PHP_EOL;\n}\n\n$name = !empty($argv[1]) ? $argv[1] : 'world';\n$hostname = !empty($argv[2]) ? $argv[2] : 'localhost:50051';\ngreet($hostname, $name);<\/code><\/pre>\n<p>\u901a\u8fc7\u7ec8\u7aef\uff0c\u542f\u52a8PHP\u5ba2\u6237\u7aef\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835140\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6211\u4eec\u53d1\u73b0\uff0cPHP\u7684\u5ba2\u6237\u7aef\u901a\u8fc7gRPC\u6210\u529f\u7684\u8fde\u63a5\u4e86Go\u670d\u52a1\u7aef\u63d0\u4f9b\u7684<em>50051<\/em>\u670d\u52a1\uff0c\u5e76\u6210\u529f\u8c03\u7528\u4e86SayHello()\u65b9\u6cd5\uff0c\u83b7\u5f97\u4e86\u8fd4\u56de\u503c\uff1a<em>Hello world<\/em><\/p>\n<h2>\u5b9e\u64cd\u6280\u5de7<\/h2>\n<p><strong>\u7eb8\u4e0a\u5f97\u6765\u7ec8\u89c9\u6d45\uff0c\u7edd\u77e5\u6b64\u4e8b\u8981\u8eac\u884c\u3002<\/strong><\/p>\n<p>\u5f3a\u70c8\u5efa\u8bae\u5927\u5bb6\u52a8\u624b\u5b9e\u64cd\uff0c\u4f7f\u7528\u81ea\u5df1\u719f\u6089\u7684\u8bed\u8a00\u5b8c\u6210gRPC\u8de8\u8bed\u8a00\u8c03\u7528\uff0c\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=uBSCyFPjHIv%2BjsjoK2hNHA%3D%3D.pgX5i6eNXJYL7GrGZi2x55twfsCQbGG4dFWdNoAkC3pfh9W41EiAjXbonthDVBRi\" rel=\"nofollow\">gRPC \u5404\u79cd\u8bed\u8a00\u6559\u7a0b\u8be6\u89e3<\/a>\u3002<strong>\u8fd9\u7bc7\u6280\u672f\u535a\u5ba2\u66f4\u9002\u5408\u5c0f\u767d\u5165\u95e8gRPC\u7684\u5f00\u53d1\uff0c\u6709\u4e2a\u6574\u4f53\u7684\u7406\u89e3\u548c\u6982\u5ff5\u3002<\/strong><\/p>\n<p>\u8fdb\u9636\u77e5\u8bc6\u70b9\u5b89\u5229\u5927\u5bb6\u770b\u5b98\u65b9\u6587\u6863\u8fdb\u884c\u5b9e\u8df5\uff1a<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=N2OOMKejeRPswBoaFz3fcw%3D%3D.u%2FLCI%2B1KmA%2Fg4%2FPacb6nvBPohJouGNxu57QKygDShz4%3D\" rel=\"nofollow\">gRPC \u5b98\u65b9\u6587\u6863\u4e2d\u6587\u7248<\/a><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=%2FaVXl15z30z%2BhPr92e93WQ%3D%3D.R0OkywtT46rUN0yopgvwllQdd1M2mT2F%2FXJwnDpkP48KhTYy46sD9japqEUs8vxN\" rel=\"nofollow\">gRPC \u5b98\u65b9\u793a\u4f8bGitHub<\/a><\/p>\n<h2>\u672c\u6587\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u5df2\u7ecf\u638c\u63e1\u4e86gRPC\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\uff0c\u53ef\u4ee5\u72ec\u7acb\u7528Go\u5b9e\u73b0\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u7684\u7f16\u5199\uff0c\u5e76\u4e14\u901a\u8fc7\u670d\u52a1\u6ce8\u518c\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u5b9e\u73b0\u53ef\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u7684gRPC\u901a\u4fe1\u3002<\/p>\n<p>\u4e3a\u4e86\u9a8c\u8bc1gRPC\u652f\u6301\u8de8\u8bed\u8a00\u8c03\u7528\u7684\u7279\u6027\uff0c\u5728\u8fdb\u9636\u5b9e\u6218\u4e2d\u53c8\u4f7f\u7528PHP\u5f00\u53d1\u4e86\u5ba2\u6237\u7aef\uff0c\u5b9e\u73b0\u4e86PHP\u5ba2\u6237\u7aef\u548cGo\u670d\u52a1\u7aef\u7684\u8fdc\u7a0b\u8de8\u8bed\u8a00\u8c03\u7528\u3002<\/p>\n<p><strong>\u517b\u6210\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u6709\u52a9\u4e8e\u51cf\u5c11\u5947\u5947\u602a\u602a\u7684\u95ee\u9898<\/strong>\uff0c\u5f3a\u70c8\u5efa\u8bae\u5927\u5bb6\u4e25\u683c\u6309\u7167\u201c\u5927\u8c61\u88c5\u51b0\u7bb1\u201d\u7684\u987a\u5e8f\u8fdb\u884cgRPC\u7684\u5f00\u53d1\uff1a<\/p>\n<p><em>1. \u5199proto\u6587\u4ef6\u5b9a\u4e49\u670d\u52a1\u548c\u6d88\u606f<\/em><\/p>\n<p><em>2. \u4f7f\u7528protoc\u5de5\u5177\u751f\u6210\u4ee3\u7801<\/em><\/p>\n<p><em>3. \u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u63d0\u4f9b\u670d\u52a1<\/em><\/p>\n<p>\u5173\u6ce8\u6211\uff0c\u4e0b\u4e00\u7bc7\u5e26\u5927\u5bb6\u73a9\u8f6cGo\u5fae\u670d\u52a1\u3002<\/p>\n<p>\u6700\u540e\uff1a<strong>\u4e07\u4e8b\u8d77\u4e8e\u5ffd\u5fae\uff0c\u91cf\u53d8\u5f15\u8d77\u8d28\u53d8\uff0c\u76f8\u4fe1\u575a\u6301\u7684\u529b\u91cf\u3002<\/strong><\/p>\n<h2>\u5173\u4e8e\u4e13\u680f<\/h2>\n<p>\u8fd1\u671f\u4f1a\u66f4\u65b0\u4e00\u7cfb\u5217Go\u5b9e\u6218\u8fdb\u9636\u7684\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\u3002<\/p>\n<p>\u8fd9\u662f\u8fd1\u671f\u4f1a\u66f4\u65b0\u6587\u7ae0\u7684\u77e5\u8bc6\u8109\u7edc\u56fe\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u5173\u6ce8\u4e00\u6ce2\uff0c\u6b22\u8fce\u65e5\u5e38\u50ac\u66f4\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042835141\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u5df2\u5b8c\u6210<\/h3>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042764979\">\u300a\u4e00\u6587\u73a9\u8f6cProtoBuf\u300b<\/a><\/p>\n<h2>\u6b22\u8fce\u50ac\u66f4<\/h2>\n<p><strong>\u5c0f\u4f19\u4f34\u4eec\u8fd8\u60f3\u770b\u54ea\u4e9b\u5185\u5bb9\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u3002<\/strong><\/p>\n<p>\u672c\u6587\u53c2\u4e0e\u4e86<a href=\"https:\/\/segmentfault.com\/a\/1190000042741155\">\u601d\u5426\u6280\u672f\u5f81\u6587<\/a>\uff0c\u6b22\u8fce\u6b63\u5728\u9605\u8bfb\u7684\u4f60\u4e5f\u52a0\u5165\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042835130\">https:\/\/segmentfault.com\/a\/1190000042835130<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e0a\u4e00\u7bc7\u6587\u7ae0\u6211\u4eec\u4ecb\u7ecd\u4e86ProtoBuf\u7684\u4f7f\u7528\uff0c\u4e0d\u4e86\u89e3ProtoBuf\u7684\u540c\u5b66\u5efa\u8bae\u5148\u8bfb\u8fd9\u7bc7\u6587\u7ae0\uff1a# \u4e00\u6587\u5e26\u4f60\u73a9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10006925","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006925"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006925\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}