{"id":206966,"date":"2025-07-08T08:52:20","date_gmt":"2025-07-08T00:52:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206966\/"},"modified":"2025-07-08T08:52:20","modified_gmt":"2025-07-08T00:52:20","slug":"go%ef%bc%9a%e8%b0%83%e7%94%a8%e5%87%bd%e6%95%b0%e6%97%b6%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%91%bd%e5%90%8d%e5%8f%82%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206966\/","title":{"rendered":"Go\uff1a\u8c03\u7528\u51fd\u6570\u65f6\u5982\u4f55\u4f7f\u7528\u547d\u540d\u53c2\u6570\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>Go\uff1a\u8c03\u7528\u51fd\u6570\u65f6\u5982\u4f55\u4f7f\u7528\u547d\u540d\u53c2\u6570\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 09:15:40<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo\uff1a\u8c03\u7528\u51fd\u6570\u65f6\u5982\u4f55\u4f7f\u7528\u547d\u540d\u53c2\u6570\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5982\u4f55\u5728\u4f7f\u7528\u547d\u540d\u53c2\u6570\u65f6\u8c03\u7528\u51fd\u6570\uff1f <\/p>\n<p>\uff08\u5982\u679c\u4e0d\u6e05\u695a\u547d\u540d\u53c2\u6570\u662f\u4ec0\u4e48\uff0c\u8fd9\u91cc\u6709\u4e00\u4e2a\u5728 python \u4e2d\u4f7f\u7528\u5b83\u4eec\u7684\u793a\u4f8b\uff09<\/p>\n<p>\u6211\u60f3\u505a\u7684\u4e8b\u60c5\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>func add(a int, b int) int {\n  return a + b\n}\n\nfunc main() {\n  c := add(a: 1, b:3)\n  return c\n}<\/pre>\n<p>\u4f46\u662f\uff0c\u4e0a\u9762\u7ed9\u4e86\u6211\u9519\u8bef\uff1a<\/p>\n<pre>unexpected :, expecting comma or )<\/pre>\n<p>\uff08\u5b83\u6307\u7684\u662f\u201ca\u201d\u540e\u9762\u7684\u201c:\u201d\uff09<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>go \u6ca1\u6709\u547d\u540d\u53c2\u6570\u3002\u6211\u6240\u77e5\u9053\u7684 go \u547d\u540d\u53c2\u6570\u4e2d\u6700\u63a5\u8fd1\u7684\u4e8b\u60c5\u662f\u4f7f\u7528\u7ed3\u6784\u4f53\u4f5c\u4e3a\u8f93\u5165\u3002\u56e0\u6b64\uff0c\u5bf9\u4e8e\u60a8\u7684\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u8fd9\u6837\u505a &#8211;<\/p>\n<pre>type Input struct {\n  A int\n  B int\n}\n\nfunc Add(in Input) int {\n  return in.A + in.B\n}\n\nfunc main() {\n  c := Add(Input{A: 1, B: 3})\n  return c\n}<\/pre>\n<p>\u7b80\u800c\u8a00\u4e4b\uff1ago \u8bed\u8a00\u4e0d\u652f\u6301\u547d\u540d\u53c2\u6570\uff0c\u4f46 ide \u652f\u6301\uff08\u89c1\u4e0b\u6587\uff09\u3002<\/p>\n<p>\u6211\u540c\u610f\u547d\u540d\u53c2\u6570\u5728 go \u4e2d\u53ef\u80fd\u5f88\u6709\u7528\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u907f\u514d\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5c31\u5728\u6628\u5929\uff0c\u6211\u7684\u6d4b\u8bd5\u53d1\u73b0\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u5176\u4e2d\u6e90\u548c\u76ee\u6807\u3002 copy()\uff08go \u5185\u7f6e\u51fd\u6570\uff09\u7684\u53c2\u6570\u4ece\u540e\u5230\u524d\u3002<\/p>\n<p>\u4f46\u662f\uff0cgo \u53ef\u80fd\u62e5\u6709\u6570\u767e\u79cd\u6709\u7528\u7684\u8bed\u8a00\u529f\u80fd\u3002\u6211\u4eec\u5c3d\u91cf\u907f\u514d\u5411\u8bed\u8a00\u6dfb\u52a0\u975e\u5fc5\u8981\u7684\u529f\u80fd\uff0c\u4ee5\u4fdd\u6301\u7b80\u5355\u3002\u4e00\u65e6\u60a8\u5728\u5927\u578b\u9879\u76ee\u4e2d\u4f7f\u7528\u4e86 go\uff0c\u60a8\u5c31\u4f1a\u975e\u5e38\u611f\u6fc0\u4e0e\u5176\u4ed6\u8bed\u8a00\u76f8\u6bd4\uff0c\u4e8b\u60c5\u8981\u7b80\u5355\u5f97\u591a\u3002 \uff08\u6211\u4e13\u4e1a\u4f7f\u7528\u8fc7\u5341\u591a\u79cd\u8bed\u8a00\uff0c\u800c go \u662f\u8fc4\u4eca\u4e3a\u6b62\u6700\u4e0d\u70e6\u4eba\u7684\u3002\uff09<\/p>\n<p>\u4f46\u5b9e\u9645\u4e0a\uff0c\u5982\u679c\u60a8\u7684 ide \u652f\u6301\uff0c\u60a8<strong>\u53ef\u4ee5<\/strong>\u62e5\u6709\u547d\u540d\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u6211\u4f7f\u7528 goland\uff0c\u5f53\u60a8\u8f93\u5165\u51fd\u6570\u7684\u53c2\u6570\u65f6\uff0c\u5b83\u4f1a\u663e\u793a\u53c2\u6570\u540d\u79f0\uff08\u6d45\u7070\u8272\uff09\uff0c\u5e76\u5728\u503c\u4e4b\u524d\u663e\u793a\u5192\u53f7\u3002\u8fd9\u6bd4\u60a8\u4e60\u60ef\u7684\u66f4\u597d\uff0c\u56e0\u4e3a\u60a8\u751a\u81f3\u4e0d\u9700\u8981\u8f93\u5165\u540d\u79f0\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\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-206966","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206966","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=206966"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206966\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}