{"id":208187,"date":"2025-07-08T15:49:28","date_gmt":"2025-07-08T07:49:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208187\/"},"modified":"2025-07-08T15:49:28","modified_gmt":"2025-07-08T07:49:28","slug":"%e8%bf%94%e5%9b%9e-golang-%e5%9c%b0%e5%9b%be%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208187\/","title":{"rendered":"\u8fd4\u56de golang \u5730\u56fe\u6570\u7ec4"},"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>\u8fd4\u56de golang \u5730\u56fe\u6570\u7ec4<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 08:06: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><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u8fd4\u56de golang \u5730\u56fe\u6570\u7ec4\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\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\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u8fd4\u56de\u5730\u56fe\u6570\u7ec4\u7684\u51fd\u6570\u3002\u6216\u8005\u5728 python \u4e2d\uff0c\u6211\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178\u5217\u8868\u3002\u6211\u8ba4\u4e3a\u6211\u9519\u8fc7\u4e86\u4e00\u4e9b\u7b80\u5355\u7684\u4e1c\u897f\uff0c\u6211\u4e0d\u77e5\u9053\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\uff0c\u5176\u4e2d\u7684\u7c7b\u578b\u662f\u6620\u5c04\u3002<\/p>\n<p>\u8fd9\u662f\u6211\u6ce8\u91ca\u6389\u4e0d\u8d77\u4f5c\u7528\u7684\u90e8\u5206\u7684\u5de5\u4f5c\u4ee3\u7801\uff1a<\/p>\n<p>https:\/\/go.dev\/play\/p\/msprp0wiab1<\/p>\n<p>\u6211\u628a\u5b83\u7559\u5728\u4e86 ^ \u793a\u4f8b\u7684 main \u4e2d\uff0c\u4f46\u6211\u771f\u6b63\u60f3\u505a\u7684\u662f\u6709\u53e6\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u6620\u5c04\u5217\u8868\uff0c\u4ee5\u4fbf\u4ee3\u7801\u7684\u53e6\u4e00\u90e8\u5206\u5e76\u8fed\u4ee3\u5b83\u4eec\uff1a<\/p>\n<pre>func theFarmInventory()[]map[string]map {\n\n    \/\/Lists of animals, this would normally be a loop in an api call for listsN\n    animalList1 := []byte(`[{\"Type\":\"Dog\",\"Name\":\"Rover\"},{\"Type\":\"Cat\",\"Name\":\"Sam\"},{\"Type\":\"Bird\",\"Name\":\"Lucy\"}]`)\n    animalList2 := []byte(`[{\"Type\":\"Hamster\",\"Name\":\"Potato\"},{\"Type\":\"Rat\",\"Name\":\"Snitch\"},{\"Type\":\"Cow\",\"Name\":\"Moo\"}]`)\n    \n    inventory1 := animalStock(animalList1)\n    inventory2 := animalStock(animalList2)\n\n    fmt.Printf(\"Inventory1 %v\\nInventory2: %v\\n\", inventory1, inventory2)\n    \n    \/\/ I would like to create a array of maps \n    var theFarm []map[string]string\n    theFarm.append(theFarm,inventory1)\n    theFarm.append(theFarm,inventory2)\n\n    fmt.Printf(\"%v\",theFarm)\n    return theFarm\n}<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u4f7f\u7528\u5185\u7f6e\u7684 \u51fd\u6570\u5c06\u9879\u76ee\u6dfb\u52a0\u5230\u5207\u7247\uff1a<\/p>\n<pre>var thefarm []map[string]string\nthefarm = append(thefarm, inventory1)\nthefarm = append(thefarm, inventory2)\nreturn thefarm<\/pre>\n<\/p>\n<p>\u53e6\u4e00\u4e2a\u9009\u62e9\u662f\u4f7f\u7528 \uff1a<\/p>\n<pre>theFram := []map[string]string{inventory1, inventory2}\nreturn theFarm<\/pre>\n<\/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\u300a\u8fd4\u56de golang \u5730\u56fe\u6570\u7ec4\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-208187","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208187","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=208187"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208187\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}