{"id":207952,"date":"2025-07-08T09:51:50","date_gmt":"2025-07-08T01:51:50","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207952\/"},"modified":"2025-07-08T09:51:50","modified_gmt":"2025-07-08T01:51:50","slug":"golang-%e5%a1%ab%e5%85%85%e5%88%87%e7%89%87%e5%8a%9f%e8%83%bd%e4%b8%8d%e8%b5%b7%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207952\/","title":{"rendered":"Golang \u586b\u5145\u5207\u7247\u529f\u80fd\u4e0d\u8d77\u4f5c\u7528"},"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>Golang \u586b\u5145\u5207\u7247\u529f\u80fd\u4e0d\u8d77\u4f5c\u7528<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 10:21:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGolang \u586b\u5145\u5207\u7247\u529f\u80fd\u4e0d\u8d77\u4f5c\u7528\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u5411\u6211\u7684\u5207\u7247\u6dfb\u52a0\u5185\u5bb9\uff0c\u4f46\u4e0d\u77e5\u4f55\u6545\uff0c\u5207\u7247\u4ece\u672a\u66f4\u65b0\u3002<\/p>\n<pre>endpointslist := make([]string, 3)\n\nfor _, route := range routes {\n    if len(route.endpoints) &gt; 0 {\n        waitgroup.add(1)\n        go endpointroutine(route, template, route.protected, &amp;waitgroup, &amp;endpointslist)\n    }\n}<\/pre>\n<p>\u6211\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7aef\u70b9\u5217\u8868\uff0c\u8fd9\u610f\u5473\u7740\u6211\u5e94\u8be5\u80fd\u591f\u5c06\u65b0\u7684\u4e1c\u897f\u5206\u914d\u5230\u6211\u8ba4\u4e3a\u7684\u5185\u5b58\u4f4d\u7f6e\u3002<\/p>\n<p>\u5728\u51fd\u6570 endpointroutine \u4e2d\u6211\u8fd9\u6837\u505a\uff1a<\/p>\n<pre>list := make([]string, 3)\n\nfor _, r := range route.endpoints {\n    list = append(list, \"some data comes here...\")\n}\n\nendpointslist = &amp;list<\/pre>\n<p>\u5f53\u6211\u5728\u6b64\u4e4b\u540e\u6267\u884c printr \u65f6\uff08\u5728\u6211\u7684\u7b2c\u4e00\u6bb5\u4ee3\u7801\u4e0b\u65b9\u548c waitgroup.wait() \u90e8\u5206\u4e4b\u540e\uff09\uff0c\u5207\u7247\u4ecd\u7136\u662f\u7a7a\u7684\u3002<\/p>\n<p>\u663e\u7136\uff0c\u6211\u73b0\u5728\u6b63\u5728\u8986\u76d6\u5207\u7247\uff0c\u6211\u7684\u6700\u7ec8\u76ee\u6807\u662f\u6dfb\u52a0\u5230\u5207\u7247\u3002\u4f46\u662f\u5f53\u6211\u5c1d\u8bd5\u4f7f\u7528\u6b64\u4ee3\u7801\u6dfb\u52a0\u65f6\uff1a<\/p>\n<pre>endpointsList = append(endpointsList, \"fdssdfsdfsdf\")<\/pre>\n<p>\u5b83\u7ed9\u4e86\u6211\u9519\u8bef\uff1a<\/p>\n<p> \u65e0\u6cd5\u4f7f\u7528\u7aef\u70b9\u5217\u8868\uff08\u7c7b\u578b *[]string\uff09\u4f5c\u4e3a []type <\/p>\n<p>\u6709\u4eba\u53ef\u4ee5\u5411\u6211\u89e3\u91ca\u4e00\u4e0b\u53ef\u80fd\u51fa\u4e86\u4ec0\u4e48\u95ee\u9898\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4f7f\u7528 <code>endpointslist = &amp;list<\/code>\uff0c\u60a8\u53ef\u4ee5\u5c06\u6307\u5411\u5207\u7247\u7684\u6307\u9488\u5206\u914d\u7ed9\u5176\u4ed6\u5207\u7247\u3002\u8981\u8bbe\u7f6e\u5207\u7247\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>*endpointsList=list<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aGolang \u586b\u5145\u5207\u7247\u529f\u80fd\u4e0d\u8d77\u4f5c\u7528\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/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-207952","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207952","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=207952"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207952\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}