{"id":207429,"date":"2025-07-08T12:16:27","date_gmt":"2025-07-08T04:16:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207429\/"},"modified":"2025-07-08T12:16:27","modified_gmt":"2025-07-08T04:16:27","slug":"goland%e4%b8%ad%e9%80%9a%e8%bf%87%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%8e%b7%e5%8f%96%e7%bb%93%e6%9e%84%e4%bd%93%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207429\/","title":{"rendered":"Goland\u4e2d\u901a\u8fc7\u5b57\u7b26\u4e32\u83b7\u53d6\u7ed3\u6784\u4f53\u5b57\u6bb5"},"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>Goland\u4e2d\u901a\u8fc7\u5b57\u7b26\u4e32\u83b7\u53d6\u7ed3\u6784\u4f53\u5b57\u6bb5<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-22 15:36:33<\/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\">\u300aGoland\u4e2d\u901a\u8fc7\u5b57\u7b26\u4e32\u83b7\u53d6\u7ed3\u6784\u4f53\u5b57\u6bb5\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>\u5728 js \u4e2d\u6211\u53ef\u4ee5\uff1a<\/p>\n<\/p>\n<pre>const str = \"Name\"\nconst obj = {\"Name\" : \"SomeName\"}\nconsole.log(obj[str])<\/pre>\n<p>\u6211\u5982\u4f55\u5728 goland \u4e2d\u505a\u5230\u8fd9\u4e00\u70b9\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u901a\u5e38\uff0c\u60a8\u4e0d\u4f1a\u5bf9 go \u4e2d\u7684\u7ed3\u6784\u6267\u884c\u6b64\u64cd\u4f5c\u3002\u5f53\u4f60\u9700\u8981\u80fd\u591f\u505a\u5230\u8fd9\u4e00\u70b9\u65f6\uff0c\u6700\u597d\u7684\u65b9\u6cd5\u901a\u5e38\u662f\u5148\u521b\u5efa\u4e00\u4e2a <code>map[string]string<\/code>\uff0c\u4f60\u53ef\u4ee5\u50cf\u5728 js \u4e2d\u4e00\u6837\u8bbf\u95ee\u5b83\u3002\u7136\u540e\u4f60\u5c06\u5b83\u8f6c\u6362\u6210\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>structfrommap := mystructtype{\n name: mymap[\"name\"], \n favoritepokemon: mymap[\"favoritepokemon\"],\n}<\/pre>\n<p>\u5982\u679c\u60a8\u786e\u5b9e\u9700\u8981\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u4e0e\u7ed3\u6784\u4f53\u4ea4\u4e92\uff0c\u60a8\u53ef\u4ee5\u5bfc\u5165\u201creflect\u201d\u5305\uff0c\u7136\u540e\u6267\u884c<\/p>\n<pre>reflect.valueof(mystruct).fieldbyname(\"name\")\n<\/pre>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"reflect\"\n)\n\nfunc main() {\n    type user struct {\n        firstName string\n        lastName  string\n    } \/\/ hire you define your struct\n\n    u := user{firstName: \"John\", lastName: \"Doe\"}\n    s := reflect.ValueOf(u)\n\n    fmt.Println(\"Name:\", s.FieldByName(\"firstName\"))\n}<\/pre>\n<p>\u4e3a\u4e86\u5e2e\u52a9\u4f60\u5f00\u59cb\u4f7f\u7528 go\uff0c\u6211\u63a8\u8350\u8fd9\u4e2a\uff1a<\/p>\n<p>\u597d\u597d\u5b66\u4e60\/\u7f16\u7801:)<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aGoland\u4e2d\u901a\u8fc7\u5b57\u7b26\u4e32\u83b7\u53d6\u7ed3\u6784\u4f53\u5b57\u6bb5\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\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-207429","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207429","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=207429"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207429\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}