{"id":206995,"date":"2025-07-08T08:49:32","date_gmt":"2025-07-08T00:49:32","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206995\/"},"modified":"2025-07-08T08:49:32","modified_gmt":"2025-07-08T00:49:32","slug":"go-%e5%a6%82%e4%bd%95%e6%9b%b4%e6%96%b0%e4%bd%9c%e4%b8%ba%e7%bb%93%e6%9e%84%e4%bd%93%e5%ad%97%e6%ae%b5%e7%9a%84%e6%98%a0%e5%b0%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206995\/","title":{"rendered":"Go &#8211; \u5982\u4f55\u66f4\u65b0\u4f5c\u4e3a\u7ed3\u6784\u4f53\u5b57\u6bb5\u7684\u6620\u5c04\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 &#8211; \u5982\u4f55\u66f4\u65b0\u4f5c\u4e3a\u7ed3\u6784\u4f53\u5b57\u6bb5\u7684\u6620\u5c04\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 12:39:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo &#8211; \u5982\u4f55\u66f4\u65b0\u4f5c\u4e3a\u7ed3\u6784\u4f53\u5b57\u6bb5\u7684\u6620\u5c04\uff1f\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u5c1d\u8bd5\u4e86\u4ee5\u4e0b\u65b9\u6cd5\u6765\u66f4\u65b0\u58f0\u660e\u4e3a\u7ed3\u6784\u5b57\u6bb5\u7684\u7a7a\u6620\u5c04\uff1a<\/p>\n<pre>package main\n\ntype MyStruct struct {\n    scoreboard map[string]int\n}\n\nfunc main() {\n    mystruct := NewMyStruct()\n    mystruct.SubmitWord('test')\n}\n\nfunc NewMyStruct() MyStruct {\n    return MyStruct{}\n}\n\nfunc (mystruct *MyStruct) SubmitWord(word string) int {\n    mystruct.scoreboard[word] = len(word)\n    return len(word)\n}<\/pre>\n<p>\u4f46\u6211\u6536\u5230 <code>exit \u72b6\u6001 2<\/code> \u7684\u9519\u8bef\u3002<\/p>\n<p>\u6709\u95ee\u9898\u7684\u884c\u662f <code>mystruct.scoreboard[word] = len(word)<\/code><\/p>\n<p>\u6211\u80fd\u627e\u5230\u7684\u4efb\u4f55\u5185\u5bb9\u4f3c\u4e4e\u90fd\u8868\u660e\u8fd9\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u6211\u8fd8\u6ca1\u6709\u627e\u5230\u5730\u56fe\u4f4d\u4e8e\u7ed3\u6784\u5185\u7684\u4efb\u4f55\u5176\u4ed6\u793a\u4f8b\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u9700\u8981\u5148\u5206\u914d\u5730\u56fe<\/p>\n<pre>package main\n\n\ntype MyStruct struct {\n    scoreboard map[string]int\n}\n\nfunc main() {\n    mystruct := NewMyStruct()\n    mystruct.SubmitWord(\"test\")\n}\n\nfunc NewMyStruct() MyStruct {\n    var x MyStruct\n    x.scoreboard=make(map[string]int)\n    return x\n}\n\nfunc (mystruct *MyStruct) SubmitWord(word string) int {\n    mystruct.scoreboard[word] = len(word)\n    return len(word)\n}<\/pre>\n<p>\u6f14\u793a\uff1a<\/p>\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\u300aGo &#8211; \u5982\u4f55\u66f4\u65b0\u4f5c\u4e3a\u7ed3\u6784\u4f53\u5b57\u6bb5\u7684\u6620\u5c04\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-206995","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206995","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=206995"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206995\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}