{"id":26235,"date":"2025-04-19T15:01:19","date_gmt":"2025-04-19T07:01:19","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/26235.html"},"modified":"2025-04-19T15:01:19","modified_gmt":"2025-04-19T07:01:19","slug":"%e5%88%a9%e7%94%a8-go-zero-%e6%90%ad%e5%bb%ba%e7%bd%91%e5%85%b3%e6%9c%8d%e5%8a%a1%e5%ae%9e%e7%8e%b0%e8%af%b7%e6%b1%82%e5%88%86%e5%8f%91%e8%87%b3%e4%b8%8d%e5%90%8c%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/26235.html","title":{"rendered":"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E5%88%A9%E7%94%A8%20go-zero%20%E6%90%AD%E5%BB%BA%E7%BD%91%E5%85%B3%E6%9C%8D%E5%8A%A1%E5%AE%9E%E7%8E%B0%E8%AF%B7%E6%B1%82%E5%88%86%E5%8F%91%E8%87%B3%E4%B8%8D%E5%90%8C%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:0px\">\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668<\/p>\n<p id=\"%E4%B8%80%E3%80%81go-zero%20%E6%A1%86%E6%9E%B6%E7%AE%80%E4%BB%8B-toc\" style=\"margin-left:40px\">\u4e00\u3001go-zero \u6846\u67b6\u7b80\u4ecb<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E5%87%86%E5%A4%87-toc\" style=\"margin-left:40px\">\u4e8c\u3001\u73af\u5883\u642d\u5efa\u51c6\u5907<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E8%AE%BE%E8%AE%A1%E7%BD%91%E5%85%B3%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%A0%B8%E5%BF%83%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:40px\">\u4e09\u3001\u8bbe\u8ba1\u7f51\u5173\u670d\u52a1\u7684\u6838\u5fc3\u903b\u8f91<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E8%AF%B7%E6%B1%82%E5%88%86%E5%8F%91%E7%9A%84%E5%85%B7%E4%BD%93%E5%AE%9E%E7%8E%B0%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:40px\">\u56db\u3001\u8bf7\u6c42\u5206\u53d1\u7684\u5177\u4f53\u5b9e\u73b0\u6b65\u9aa4<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8%E4%B8%8E%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:40px\">\u4e94\u3001\u670d\u52a1\u542f\u52a8\u4e0e\u6d4b\u8bd5<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B-toc\" style=\"margin-left:40px\">\u516d\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/p>\n<p id=\"%E4%B8%83%E3%80%81go-zero%20%E7%BD%91%E5%85%B3%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%AE%8C%E6%95%B4%E7%9B%AE%E5%BD%95%E4%B8%8E%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:40px\">\u4e03\u3001go-zero \u7f51\u5173\u5fae\u670d\u52a1\u5b8c\u6574\u76ee\u5f55\u4e0e\u4ee3\u7801\u793a\u4f8b<\/p>\n<p id=\"%EF%BC%88%E4%B8%80%EF%BC%89%E5%AE%8C%E6%95%B4%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:80px\">&#xff08;\u4e00&#xff09;\u5b8c\u6574\u76ee\u5f55\u7ed3\u6784<\/p>\n<p id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:80px\">&#xff08;\u4e8c&#xff09;\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/p>\n<hr id=\"hr-toc\" \/>\n<\/p>\n<p>\u5728\u73b0\u4ee3\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u4e2d&#xff0c;\u7f51\u5173\u4f5c\u4e3a\u6d41\u91cf\u5165\u53e3&#xff0c;\u627f\u62c5\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272&#xff0c;\u5b83\u8d1f\u8d23\u5c06\u5916\u90e8\u8bf7\u6c42\u9ad8\u6548\u4e14\u667a\u80fd\u5730\u5206\u53d1\u5230\u540e\u7aef\u4e0d\u540c\u7684\u670d\u52a1\u5668\u7fa4\u7ec4&#xff0c;\u4ee5\u6b64\u4fdd\u969c\u7cfb\u7edf\u7684\u9ad8\u53ef\u7528\u6027\u3001\u6269\u5c55\u6027\u4e0e\u7075\u6d3b\u6027\u3002\u4eca\u5929&#xff0c;\u6211\u4eec\u5c31\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u501f\u52a9\u5f3a\u5927\u7684 go-zero \u6846\u67b6\u7f16\u5199\u4e00\u4e2a\u7f51\u5173\u670d\u52a1&#xff0c;\u8fbe\u6210\u7cbe\u51c6\u7684\u8bf7\u6c42\u5206\u53d1\u529f\u80fd\u3002<\/p>\n<h3 id=\"%E4%B8%80%E3%80%81go-zero%20%E6%A1%86%E6%9E%B6%E7%AE%80%E4%BB%8B\">\u4e00\u3001go-zero \u6846\u67b6\u7b80\u4ecb<\/h3>\n<\/p>\n<p>go-zero \u662f\u4e00\u6b3e\u96c6\u6210\u4e86\u8bf8\u591a\u9ad8\u6548\u7279\u6027\u3001\u4e13\u4e3a\u4e91\u539f\u751f\u8bbe\u8ba1\u7684\u5f00\u6e90\u6846\u67b6&#xff0c;\u5b83\u62e5\u6709\u7b80\u6d01\u6613\u7528\u7684 API\u3001\u5b8c\u5907\u7684\u5fae\u670d\u52a1\u6cbb\u7406\u80fd\u529b&#xff08;\u5982\u7194\u65ad\u3001\u9650\u6d41\u3001\u964d\u7ea7\u7b49&#xff09;&#xff0c;\u5185\u7f6e\u7684 rpc\u3001http \u7b49\u6a21\u5757\u80fd\u5feb\u901f\u642d\u5efa\u5404\u7c7b\u670d\u52a1\u57fa\u7840\u67b6\u6784&#xff0c;\u5176\u5bf9\u6027\u80fd\u6781\u81f4\u8ffd\u6c42\u7684\u8bbe\u8ba1\u7406\u5ff5&#xff0c;\u4f7f\u5f97\u5728\u6784\u5efa\u7f51\u5173\u8fd9\u7c7b\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u670d\u52a1\u65f6\u5177\u5907\u5929\u7136\u4f18\u52bf\u3002<\/p>\n<h3 id=\"%E4%BA%8C%E3%80%81%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E5%87%86%E5%A4%87\">\u4e8c\u3001\u73af\u5883\u642d\u5efa\u51c6\u5907<\/h3>\n<\/p>\n<li>\u5b89\u88c5 Golang&#xff1a;\u786e\u4fdd\u672c\u5730\u73af\u5883\u5df2\u5b89\u88c5\u7b26\u5408\u8981\u6c42\u7684 Golang \u7248\u672c&#xff08;\u5efa\u8bae 1.16 \u53ca\u4ee5\u4e0a&#xff09;&#xff0c;\u5728\u5b98\u7f51&#xff08;https:\/\/golang.org\/dl\/&#xff09;\u4e0b\u8f7d\u5bf9\u5e94\u7cfb\u7edf\u7684\u5b89\u88c5\u5305&#xff0c;\u6309\u6307\u5f15\u5b8c\u6210\u5b89\u88c5&#xff0c;\u914d\u7f6e\u597d\u00a0GOPATH\u00a0\u548c\u00a0GOROOT\u00a0\u73af\u5883\u53d8\u91cf&#xff0c;\u4ee5\u4fbf\u540e\u7eed\u4ee3\u7801\u7f16\u8bd1\u4e0e\u4f9d\u8d56\u7ba1\u7406\u3002<\/li>\n<li>\u5b89\u88c5 go-zero&#xff1a;\u901a\u8fc7\u547d\u4ee4\u00a0go install github.com\/zeromicro\/go-zero\/tools\/goctl&#064;latest\u00a0\u5b89\u88c5 go-zero \u7684\u4ee3\u7801\u751f\u6210\u5de5\u5177\u00a0goctl&#xff0c;\u5b83\u80fd\u5927\u5e45\u63d0\u5347\u7f16\u5199\u670d\u52a1\u4ee3\u7801\u7684\u6548\u7387&#xff0c;\u5feb\u901f\u751f\u6210\u6a21\u677f\u4ee3\u7801\u7ed3\u6784&#xff0c;\u5982 API\u3001rpc \u670d\u52a1\u5b9a\u4e49\u4e0e\u5b9e\u73b0\u7b49\u57fa\u7840\u6846\u67b6\u4ee3\u7801\u3002<\/li>\n<h3 id=\"%E4%B8%89%E3%80%81%E8%AE%BE%E8%AE%A1%E7%BD%91%E5%85%B3%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%A0%B8%E5%BF%83%E9%80%BB%E8%BE%91\">\u4e09\u3001\u8bbe\u8ba1\u7f51\u5173\u670d\u52a1\u7684\u6838\u5fc3\u903b\u8f91<\/h3>\n<\/p>\n<li>\u8def\u7531\u5b9a\u4e49&#xff1a;\u5728 go-zero \u7684\u00a0http\u00a0\u6a21\u5757\u91cc&#xff0c;\u5229\u7528\u00a0engine :&#061; rest.MustNewServer(c.RestConf)\u00a0\u521b\u5efa HTTP \u670d\u52a1\u5b9e\u4f8b\u540e&#xff0c;\u901a\u8fc7\u7c7b\u4f3c\u00a0engine.AddRoutes(rest.Route{ Method: http.MethodGet, Path: &#034;\/user\/{id}&#034;, Handler: userHandler})\u00a0\u7684\u65b9\u5f0f\u5b9a\u4e49\u8def\u7531\u89c4\u5219\u3002\u8fd9\u91cc\u7684\u00a0userHandler\u00a0\u662f\u81ea\u5b9a\u4e49\u7684\u5904\u7406\u51fd\u6570&#xff0c;Path\u00a0\u4e2d\u7684\u52a8\u6001\u53c2\u6570\u00a0{id}\u00a0\u53ef\u7075\u6d3b\u6355\u83b7\u8bf7\u6c42\u8def\u5f84\u4e2d\u7684\u5173\u952e\u4fe1\u606f&#xff0c;\u65b9\u4fbf\u540e\u7eed\u4e1a\u52a1\u903b\u8f91\u5904\u7406\u4e0e\u8bf7\u6c42\u8f6c\u53d1\u5224\u65ad\u3002<\/li>\n<li>\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u9009\u62e9&#xff1a;\u9488\u5bf9\u540e\u7aef\u591a\u53f0\u670d\u52a1\u5668&#xff0c;go-zero \u63d0\u4f9b\u5185\u7f6e\u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5&#xff0c;\u50cf\u5e38\u89c1\u7684\u00a0roundRobin&#xff08;\u8f6e\u8be2&#xff09;\u3001weightedRoundRobin&#xff08;\u52a0\u6743\u8f6e\u8be2&#xff0c;\u4f9d\u636e\u670d\u52a1\u5668\u6027\u80fd\u914d\u7f6e\u6743\u91cd&#xff09;\u7b49\u3002\u5728\u914d\u7f6e\u6587\u4ef6\u00a0etc\/gateway.yaml\u00a0\u4e2d&#xff0c;\u5bf9\u540e\u7aef\u670d\u52a1\u5668\u5217\u8868\u00a0targets\u00a0\u5b57\u6bb5\u5173\u8054\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u914d\u7f6e&#xff0c;\u793a\u4f8b&#xff1a;<\/li>\n<p>Endpoints:<br \/>\n  &#8211; Name: backend-service<br \/>\n    Targets:<br \/>\n      &#8211; &#034;http:\/\/server1:8080&#034;, weight: 1<br \/>\n      &#8211; &#034;http:\/\/server2:8080&#034;, weight: 2<br \/>\n    LBPolicy: weightedRoundRobin<\/p>\n<p>\u4ee5\u6b64\u8ba9\u7f51\u5173\u6309\u8bbe\u5b9a\u7b56\u7565\u5206\u53d1\u8bf7\u6c42&#xff0c;\u5408\u7406\u5206\u914d\u6d41\u91cf\u5230\u4e0d\u540c\u540e\u7aef\u5b9e\u4f8b&#xff0c;\u63d0\u5347\u6574\u4f53\u670d\u52a1\u541e\u5410\u91cf\u4e0e\u6027\u80fd\u5747\u8861\u6027\u3002<\/p>\n<h3 id=\"%E5%9B%9B%E3%80%81%E8%AF%B7%E6%B1%82%E5%88%86%E5%8F%91%E7%9A%84%E5%85%B7%E4%BD%93%E5%AE%9E%E7%8E%B0%E6%AD%A5%E9%AA%A4\">\u56db\u3001\u8bf7\u6c42\u5206\u53d1\u7684\u5177\u4f53\u5b9e\u73b0\u6b65\u9aa4<\/h3>\n<\/p>\n<li>\u89e3\u6790\u8bf7\u6c42&#xff1a;\u5728\u8def\u7531\u5904\u7406\u51fd\u6570&#xff08;\u5982\u4e0a\u8ff0\u00a0userHandler&#xff09;\u4e2d&#xff0c;\u501f\u52a9\u00a0ctx.Request()\u00a0\u83b7\u53d6\u00a0http.Request\u00a0\u5b9e\u4f8b&#xff0c;\u5206\u6790\u8bf7\u6c42\u65b9\u6cd5\u3001\u8def\u5f84\u3001\u5934\u90e8\u4fe1\u606f\u7b49\u5173\u952e\u8981\u7d20&#xff0c;\u4f9d\u6b64\u5224\u65ad\u8bf7\u6c42\u5e94\u8f6c\u53d1\u5230\u54ea\u7c7b\u540e\u7aef\u670d\u52a1\u7fa4\u7ec4\u3002\u4f8b\u5982&#xff0c;\u5bf9\u4e8e\u00a0\/product\u00a0\u5f00\u5934\u7684\u8bf7\u6c42\u8def\u5f84&#xff0c;\u8ba1\u5212\u8f6c\u53d1\u81f3\u4ea7\u54c1\u670d\u52a1\u540e\u7aef\u96c6\u7fa4\u3002<\/li>\n<li>\u53cd\u5411\u4ee3\u7406\u914d\u7f6e\u4e0e\u8f6c\u53d1&#xff1a;\u5229\u7528\u00a0net\/http\u00a0\u5e93\u5185\u7f6e\u7684\u00a0httputil.ReverseProxy\u00a0\u7ed3\u6784\u4f53&#xff0c;\u914d\u7f6e\u00a0Transport\u3001Director\u00a0\u7b49\u5c5e\u6027\u5b9e\u73b0\u53cd\u5411\u4ee3\u7406\u529f\u80fd\u3002\u793a\u4f8b\u4ee3\u7801\u7247\u6bb5\u5982\u4e0b&#xff1a;<\/li>\n<p>proxy :&#061; &amp;httputil.ReverseProxy{<br \/>\n    Director: func(req *http.Request) {<br \/>\n        \/\/ \u4fee\u6539\u8bf7\u6c42\u76ee\u6807\u5730\u5740&#xff0c;\u6307\u5411\u9009\u5b9a\u540e\u7aef\u670d\u52a1\u5668<br \/>\n        req.URL.Scheme &#061; &#034;http&#034;<br \/>\n        req.URL.Host &#061; &#034;selected-backend-server:port&#034;<br \/>\n    },<br \/>\n    Transport: &amp;http.Transport{<br \/>\n        \/\/ \u53ef\u914d\u7f6e\u8fde\u63a5\u6c60\u3001\u8d85\u65f6\u7b49\u4f20\u8f93\u5c42\u53c2\u6570&#xff0c;\u4f18\u5316\u6027\u80fd<br \/>\n    },<br \/>\n}<br \/>\nproxy.ServeHTTP(w, req)<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5c06\u8fdb\u5165\u7f51\u5173\u7684\u8bf7\u6c42\u6309\u8bbe\u5b9a\u89c4\u5219\u4fee\u6539\u8bf7\u6c42\u76ee\u6807&#xff0c;\u65e0\u7f1d\u8f6c\u53d1\u81f3\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u5e76\u5904\u7406\u54cd\u5e94\u56de\u4f20&#xff0c;\u5b8c\u6210\u5b8c\u6574\u7684\u8bf7\u6c42\u5206\u53d1\u6d41\u7a0b\u95ed\u73af\u3002<\/p>\n<h3 id=\"%E4%BA%94%E3%80%81%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8%E4%B8%8E%E6%B5%8B%E8%AF%95\">\u4e94\u3001\u670d\u52a1\u542f\u52a8\u4e0e\u6d4b\u8bd5<\/h3>\n<\/p>\n<li>\u542f\u52a8\u7f51\u5173\u670d\u52a1&#xff1a;\u5728\u9879\u76ee\u6839\u76ee\u5f55&#xff0c;\u901a\u8fc7\u00a0go run gateway.go&#xff08;\u5047\u8bbe\u00a0gateway.go\u00a0\u662f\u4e3b\u5165\u53e3\u6587\u4ef6&#xff09;\u547d\u4ee4\u542f\u52a8\u7f51\u5173\u670d\u52a1&#xff0c;\u5b83\u4f1a\u4f9d\u636e\u914d\u7f6e\u52a0\u8f7d\u8def\u7531\u3001\u8fde\u63a5\u540e\u7aef\u670d\u52a1&#xff0c;\u76d1\u542c\u6307\u5b9a\u7aef\u53e3&#xff08;\u5982\u00a08888&#xff09;\u7b49\u5f85\u5916\u90e8\u8bf7\u6c42\u3002<\/li>\n<li>\u6d4b\u8bd5\u8bf7\u6c42\u5206\u53d1\u6548\u679c&#xff1a;\u8fd0\u7528\u5de5\u5177\u5982\u00a0curl\u00a0\u6216\u8005\u00a0Postman&#xff0c;\u5411\u7f51\u5173\u670d\u52a1\u53d1\u9001\u5404\u7c7b\u6a21\u62df\u8bf7\u6c42&#xff0c;\u89c2\u5bdf\u65e5\u5fd7\u8f93\u51fa&#xff08;\u5728\u7f51\u5173\u4e0e\u540e\u7aef\u670d\u52a1\u5668\u7aef\u5206\u522b\u8bb0\u5f55\u8bf7\u6c42\u63a5\u6536\u4e0e\u5904\u7406\u65e5\u5fd7&#xff09;&#xff0c;\u68c0\u67e5\u8bf7\u6c42\u662f\u5426\u6309\u9884\u671f\u8def\u7531\u89c4\u5219\u4e0e\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u5206\u53d1\u5230\u4e0d\u540c\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u9a8c\u8bc1\u54cd\u5e94\u6570\u636e\u51c6\u786e\u6027\u4e0e\u5b8c\u6574\u6027&#xff0c;\u5bf9\u51fa\u73b0\u7684\u95ee\u9898\u53ca\u65f6\u6392\u67e5\u8c03\u6574&#xff0c;\u4f18\u5316\u7f51\u5173\u914d\u7f6e\u4e0e\u4ee3\u7801\u903b\u8f91\u3002<\/li>\n<h3 id=\"%E5%85%AD%E3%80%81%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B\">\u516d\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/h3>\n<\/p>\n<p>\u501f\u52a9 go-zero \u6846\u67b6\u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1&#xff0c;\u4e0d\u4ec5\u9ad8\u6548\u5229\u7528\u6846\u67b6\u5185\u7f6e\u529f\u80fd\u7b80\u5316\u5f00\u53d1\u6d41\u7a0b\u3001\u4fdd\u969c\u6027\u80fd&#xff0c;\u8fd8\u4e3a\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u63d0\u4f9b\u7a33\u5065\u6d41\u91cf\u5165\u53e3\u652f\u6491\u3002\u540e\u7eed\u53ef\u6df1\u5165\u63a2\u7d22\u96c6\u6210\u66f4\u591a\u5b89\u5168\u8ba4\u8bc1&#xff08;\u5982 JWT \u9274\u6743\u5728\u7f51\u5173\u5c42\u7edf\u4e00\u6821\u9a8c&#xff09;\u3001\u52a8\u6001\u914d\u7f6e\u66f4\u65b0&#xff08;\u5b9e\u65f6\u8c03\u6574\u540e\u7aef\u670d\u52a1\u5668\u5217\u8868\u4e0e\u7b56\u7565&#xff09;\u7b49\u62d3\u5c55\u529f\u80fd&#xff0c;\u6301\u7eed\u5f3a\u5316\u7f51\u5173\u670d\u52a1\u5728\u590d\u6742\u4e1a\u52a1\u573a\u666f\u4e0b\u7684\u9002\u7528\u6027\u4e0e\u7ba1\u63a7\u529b&#xff0c;\u52a9\u529b\u7cfb\u7edf\u67b6\u6784\u5411\u66f4\u9ad8\u6548\u3001\u667a\u80fd\u65b9\u5411\u6f14\u8fdb\u3002<\/p>\n<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u4e3a\u5927\u5bb6\u5728\u4f7f\u7528 go-zero \u6784\u5efa\u7f51\u5173\u670d\u52a1\u65f6\u62e8\u5f00\u8ff7\u96fe&#xff0c;\u5f00\u542f\u987a\u7545\u7684\u5f00\u53d1\u4e4b\u65c5&#xff0c;\u82e5\u6709\u7591\u95ee\u4e0e\u89c1\u89e3&#xff0c;\u6b22\u8fce\u968f\u65f6\u4ea4\u6d41\u5206\u4eab&#xff01;<\/p>\n<h3 id=\"%E4%B8%83%E3%80%81go-zero%20%E7%BD%91%E5%85%B3%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%AE%8C%E6%95%B4%E7%9B%AE%E5%BD%95%E4%B8%8E%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B\">\u4e03\u3001go-zero \u7f51\u5173\u5fae\u670d\u52a1\u5b8c\u6574\u76ee\u5f55\u4e0e\u4ee3\u7801\u793a\u4f8b<\/h3>\n<h4 id=\"%EF%BC%88%E4%B8%80%EF%BC%89%E5%AE%8C%E6%95%B4%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84\">&#xff08;\u4e00&#xff09;\u5b8c\u6574\u76ee\u5f55\u7ed3\u6784<\/h4>\n<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5178\u578b\u7684\u57fa\u4e8e go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u9879\u76ee\u7684\u76ee\u5f55\u7ed3\u6784&#xff0c;\u6e05\u6670\u5408\u7406\u7684\u76ee\u5f55\u5e03\u5c40\u6709\u52a9\u4e8e\u9879\u76ee\u7684\u7ef4\u62a4\u4e0e\u6269\u5c55\u3002<\/p>\n<\/p>\n<p>\u251c\u2500\u2500 etc<br \/>\n\u2502   \u2514\u2500\u2500 gateway.yaml  \/\/ \u7f51\u5173\u670d\u52a1\u914d\u7f6e\u6587\u4ef6&#xff0c;\u5b58\u653e\u7aef\u53e3\u3001\u8d1f\u8f7d\u5747\u8861\u3001\u540e\u7aef\u670d\u52a1\u5730\u5740\u7b49\u914d\u7f6e\u4fe1\u606f<br \/>\n\u251c\u2500\u2500 gateway<br \/>\n\u2502   \u251c\u2500\u2500 gateway.go  \/\/ \u7f51\u5173\u670d\u52a1\u4e3b\u7a0b\u5e8f\u5165\u53e3&#xff0c;\u5b9a\u4e49\u8def\u7531\u3001\u542f\u52a8\u670d\u52a1\u7b49\u903b\u8f91<br \/>\n\u2502   \u2514\u2500\u2500 handler<br \/>\n\u2502       \u2514\u2500\u2500 userHandler.go  \/\/ \u81ea\u5b9a\u4e49\u8def\u7531\u5904\u7406\u51fd\u6570\u5b9e\u73b0\u6587\u4ef6&#xff0c;\u5904\u7406\u8bf7\u6c42\u5e76\u8f6c\u53d1\u5230\u540e\u7aef<br \/>\n\u2514\u2500\u2500 internal<br \/>\n    \u2514\u2500\u2500 types<br \/>\n        \u2514\u2500\u2500 types.go  \/\/ \u53ef\u5b9a\u4e49\u4e00\u4e9b\u5185\u90e8\u5171\u7528\u7684\u6570\u636e\u7c7b\u578b\u7ed3\u6784\u4f53\u7b49&#xff0c;\u6309\u9700\u6dfb\u52a0\u5185\u5bb9<\/p>\n<h4 id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B\">&#xff08;\u4e8c&#xff09;\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/h4>\n<\/p>\n<p>gateway.go&#xff08;\u4e3b\u7a0b\u5e8f\u5165\u53e3\u6587\u4ef6&#xff09;<\/p>\n<\/p>\n<p>package main<\/p>\n<p>import (<br \/>\n    &#034;net\/http&#034;<br \/>\n    &#034;github.com\/zeromicro\/go-zero\/rest&#034;<br \/>\n    &#034;github.com\/zeromicro\/go-zero\/rest\/httputil&#034;<br \/>\n    &#034;gateway\/handler&#034;<br \/>\n)<\/p>\n<p>func main() {<br \/>\n    c :&#061; rest.RestConf{<br \/>\n        ServiceConf: rest.ServiceConf{<br \/>\n            Name: &#034;gateway-service&#034;,<br \/>\n            Port: 8888,<br \/>\n        },<br \/>\n    }<br \/>\n    engine :&#061; rest.MustNewServer(c.RestConf)<br \/>\n    \/\/ \u5b9a\u4e49\u591a\u4e2a\u8def\u7531\u89c4\u5219\u793a\u4f8b&#xff0c;\u8fd9\u91cc\u6dfb\u52a0\u4e86 \/user\/{id} \u548c \/product\/{id} \u4e24\u6761\u8def\u7531<br \/>\n    engine.AddRoutes(rest.Route{<br \/>\n        Method:  http.MethodGet,<br \/>\n        Path:    &#034;\/user\/{id}&#034;,<br \/>\n        Handler: handler.UserHandler,<br \/>\n    }, rest.Route{<br \/>\n        Method:  http.MethodGet,<br \/>\n        Path:    &#034;\/product\/{id}&#034;,<br \/>\n        Handler: handler.ProductHandler,<br \/>\n    })<br \/>\n    defer engine.Stop()<br \/>\n    engine.Start()<br \/>\n}<\/p>\n<p>handler\/userHandler.go&#xff08;\u7528\u6237\u76f8\u5173\u8def\u7531\u5904\u7406\u51fd\u6570\u5b9e\u73b0\u6587\u4ef6&#xff09;<\/p>\n<\/p>\n<p>package handler<\/p>\n<p>import (<br \/>\n    &#034;net\/http&#034;<br \/>\n    &#034;github.com\/zeromicro\/go-zero\/rest\/httputil&#034;<br \/>\n)<\/p>\n<p>\/\/ UserHandler \u5904\u7406 \/user\/{id} \u8def\u7531\u8bf7\u6c42&#xff0c;\u8fd9\u91cc\u7b80\u5355\u793a\u4f8b\u8f6c\u53d1\u903b\u8f91&#xff0c;\u5b9e\u9645\u6309\u9700\u6df1\u5ea6\u5b9a\u5236<br \/>\nfunc UserHandler(ctx *rest.Context) {<br \/>\n    req :&#061; ctx.Request()<br \/>\n    proxy :&#061; &amp;httputil.ReverseProxy{<br \/>\n        Director: func(proxyReq *http.Request) {<br \/>\n            \/\/ \u5047\u8bbe\u9ed8\u8ba4\u8f6c\u53d1\u5230 server1&#xff0c;\u5b9e\u9645\u6309\u4e1a\u52a1\u903b\u8f91\u9009\u540e\u7aef\u670d\u52a1\u5668<br \/>\n            proxyReq.URL.Scheme &#061; &#034;http&#034;<br \/>\n            proxyReq.URL.Host &#061; &#034;server1:8080&#034;<br \/>\n        },<br \/>\n        Transport: &amp;http.Transport{},<br \/>\n    }<br \/>\n    proxy.ServeHTTP(ctx.ResponseWriter, req)<br \/>\n}<\/p>\n<p>handler\/productHandler.go&#xff08;\u4ea7\u54c1\u76f8\u5173\u8def\u7531\u5904\u7406\u51fd\u6570\u5b9e\u73b0\u6587\u4ef6&#xff09;<\/p>\n<\/p>\n<p>package handler<\/p>\n<p>import (<br \/>\n    &#034;net\/http&#034;<br \/>\n    &#034;github.com\/zeromicro\/go-zero\/rest\/httputil&#034;<br \/>\n)<\/p>\n<p>\/\/ ProductHandler \u5904\u7406 \/product\/{id} \u8def\u7531\u8bf7\u6c42&#xff0c;\u6309\u89c4\u5219\u8f6c\u53d1\u5230\u4ea7\u54c1\u670d\u52a1\u540e\u7aef<br \/>\nfunc ProductHandler(ctx *rest.Context) {<br \/>\n    req :&#061; ctx.Request()<br \/>\n    proxy :&#061; &amp;httputil.ReverseProxy{<br \/>\n        Director: func(proxyReq *http.Request) {<br \/>\n            proxyReq.URL.Scheme &#061; &#034;http&#034;<br \/>\n            proxyReq.URL.Host &#061; &#034;product-server:8080&#034;<br \/>\n        },<br \/>\n        Transport: &amp;http.Transport{},<br \/>\n    }<br \/>\n    proxy.ServeHTTP(ctx.ResponseWriter, req)<br \/>\n}<\/p>\n<p>etc\/gateway.yaml&#xff08;\u914d\u7f6e\u6587\u4ef6&#xff09;<\/p>\n<\/p>\n<p>Name: gateway-service<br \/>\nPort: 8888<br \/>\nEndpoints:<br \/>\n  &#8211; Name: backend-service<br \/>\n    Targets:<br \/>\n      &#8211; &#034;http:\/\/server1:8080&#034;, weight: 1<br \/>\n      &#8211; &#034;http:\/\/server2:8080&#034;, weight: 2<br \/>\n    LBPolicy: weightedRoundRobin<br \/>\n  &#8211; Name: product-service<br \/>\n    Targets:<br \/>\n      &#8211; &#034;http:\/\/product-server1:8080&#034;, weight: 1<br \/>\n      &#8211; &#034;http:\/\/product-server2:8080&#034;, weight: 2<br \/>\n    LBPolicy: weightedRoundRobin<\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u6784\u5efa\u4e86\u4e00\u4e2a\u57fa\u7840\u7684 go-zero \u7f51\u5173\u5fae\u670d\u52a1\u793a\u4f8b&#xff0c;\u6db5\u76d6\u4e86\u8def\u7531\u5b9a\u4e49\u3001\u57fa\u4e8e\u89c4\u5219\u7684\u8bf7\u6c42\u8f6c\u53d1\u3001\u8d1f\u8f7d\u5747\u8861\u914d\u7f6e\u4ee5\u53ca\u7b80\u5355\u6e05\u6670\u7684\u76ee\u5f55\u7ed3\u6784\u3002\u5728\u5b9e\u9645\u5e94\u7528\u573a\u666f\u4e2d&#xff0c;\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u4e1a\u52a1\u9700\u6c42&#xff0c;\u8fdb\u4e00\u6b65\u4e30\u5bcc\u8def\u7531\u5904\u7406\u51fd\u6570\u903b\u8f91&#xff08;\u5982\u9274\u6743\u3001\u65e5\u5fd7\u8bb0\u5f55\u8be6\u7ec6\u8bf7\u6c42\u4fe1\u606f\u7b49&#xff09;\u3001\u7cbe\u7ec6\u8c03\u6574\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u3001\u62d3\u5c55\u66f4\u591a\u670d\u52a1\u5bf9\u63a5\u53ca\u4f18\u5316\u914d\u7f6e&#xff0c;\u4ee5\u6b64\u5951\u5408\u590d\u6742\u591a\u6837\u7684\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u8981\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf8\u6b21\u3002go-zero \u662f\u4e00\u6b3e\u96c6\u6210\u4e86\u8bf8\u591a\u9ad8\u6548\u7279\u6027\u3001\u4e13\u4e3a\u4e91\u539f\u751f\u8bbe\u8ba1\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u62e5\u6709\u7b80\u6d01\u6613\u7528\u7684 API\u3001\u5b8c\u5907\u7684\u5fae\u670d\u52a1\u6cbb\u7406\u80fd\u529b\uff08\u5982\u7194\u65ad\u3001\u9650\u6d41\u3001\u964d\u7ea7\u7b49\uff09\uff0c\u5185\u7f6e\u7684 rpc\u3001http \u7b49\u6a21\u5757\u80fd\u5feb\u901f\u642d\u5efa\u5404\u7c7b\u670d\u52a1\u57fa\u7840\u67b6\u6784\uff0c\u5176\u5bf9\u6027\u80fd\u6781\u81f4\u8ffd\u6c42\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u4f7f\u5f97\u5728\u6784\u5efa\u7f51\u5173\u8fd9\u7c7b\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u670d\u52a1\u65f6\u5177\u5907\u5929\u7136\u4f18\u52bf\u3002\u501f\u52a9 go-zero \u6846\u67b6\u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\uff0c\u4e0d\u4ec5\u9ad8\u6548\u5229\u7528\u6846\u67b6\u5185\u7f6e\u529f\u80fd\u7b80\u5316\u5f00\u53d1\u6d41\u7a0b\u3001\u4fdd\u969c\u6027\u80fd\uff0c\u8fd8\u4e3a\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u63d0\u4f9b\u7a33\u5065\u6d41\u91cf\u5165\u53e3\u652f\u6491\u3002_go-zero\u7f51\u5173<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[746,190,43],"topic":[],"class_list":["post-26235","post","type-post","status-publish","format-standard","hentry","category-server","tag-golang","tag-190","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/26235.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf8\u6b21\u3002go-zero \u662f\u4e00\u6b3e\u96c6\u6210\u4e86\u8bf8\u591a\u9ad8\u6548\u7279\u6027\u3001\u4e13\u4e3a\u4e91\u539f\u751f\u8bbe\u8ba1\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u62e5\u6709\u7b80\u6d01\u6613\u7528\u7684 API\u3001\u5b8c\u5907\u7684\u5fae\u670d\u52a1\u6cbb\u7406\u80fd\u529b\uff08\u5982\u7194\u65ad\u3001\u9650\u6d41\u3001\u964d\u7ea7\u7b49\uff09\uff0c\u5185\u7f6e\u7684 rpc\u3001http \u7b49\u6a21\u5757\u80fd\u5feb\u901f\u642d\u5efa\u5404\u7c7b\u670d\u52a1\u57fa\u7840\u67b6\u6784\uff0c\u5176\u5bf9\u6027\u80fd\u6781\u81f4\u8ffd\u6c42\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u4f7f\u5f97\u5728\u6784\u5efa\u7f51\u5173\u8fd9\u7c7b\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u670d\u52a1\u65f6\u5177\u5907\u5929\u7136\u4f18\u52bf\u3002\u501f\u52a9 go-zero \u6846\u67b6\u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\uff0c\u4e0d\u4ec5\u9ad8\u6548\u5229\u7528\u6846\u67b6\u5185\u7f6e\u529f\u80fd\u7b80\u5316\u5f00\u53d1\u6d41\u7a0b\u3001\u4fdd\u969c\u6027\u80fd\uff0c\u8fd8\u4e3a\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u63d0\u4f9b\u7a33\u5065\u6d41\u91cf\u5165\u53e3\u652f\u6491\u3002_go-zero\u7f51\u5173\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/26235.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T07:01:19+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/26235.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/26235.html\",\"name\":\"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T07:01:19+00:00\",\"dateModified\":\"2025-04-19T07:01:19+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/26235.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/26235.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/26235.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/26235.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf8\u6b21\u3002go-zero \u662f\u4e00\u6b3e\u96c6\u6210\u4e86\u8bf8\u591a\u9ad8\u6548\u7279\u6027\u3001\u4e13\u4e3a\u4e91\u539f\u751f\u8bbe\u8ba1\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u62e5\u6709\u7b80\u6d01\u6613\u7528\u7684 API\u3001\u5b8c\u5907\u7684\u5fae\u670d\u52a1\u6cbb\u7406\u80fd\u529b\uff08\u5982\u7194\u65ad\u3001\u9650\u6d41\u3001\u964d\u7ea7\u7b49\uff09\uff0c\u5185\u7f6e\u7684 rpc\u3001http \u7b49\u6a21\u5757\u80fd\u5feb\u901f\u642d\u5efa\u5404\u7c7b\u670d\u52a1\u57fa\u7840\u67b6\u6784\uff0c\u5176\u5bf9\u6027\u80fd\u6781\u81f4\u8ffd\u6c42\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u4f7f\u5f97\u5728\u6784\u5efa\u7f51\u5173\u8fd9\u7c7b\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u670d\u52a1\u65f6\u5177\u5907\u5929\u7136\u4f18\u52bf\u3002\u501f\u52a9 go-zero \u6846\u67b6\u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\uff0c\u4e0d\u4ec5\u9ad8\u6548\u5229\u7528\u6846\u67b6\u5185\u7f6e\u529f\u80fd\u7b80\u5316\u5f00\u53d1\u6d41\u7a0b\u3001\u4fdd\u969c\u6027\u80fd\uff0c\u8fd8\u4e3a\u5206\u5e03\u5f0f\u7cfb\u7edf\u67b6\u6784\u63d0\u4f9b\u7a33\u5065\u6d41\u91cf\u5165\u53e3\u652f\u6491\u3002_go-zero\u7f51\u5173","og_url":"https:\/\/www.wsisp.com\/helps\/26235.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T07:01:19+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/26235.html","url":"https:\/\/www.wsisp.com\/helps\/26235.html","name":"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T07:01:19+00:00","dateModified":"2025-04-19T07:01:19+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/26235.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/26235.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/26235.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5229\u7528 go-zero \u642d\u5efa\u7f51\u5173\u670d\u52a1\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u81f3\u4e0d\u540c\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/26235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=26235"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/26235\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=26235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=26235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=26235"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=26235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}