{"id":48566,"date":"2024-12-02T12:14:54","date_gmt":"2024-12-02T04:14:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48566\/"},"modified":"2024-12-02T12:14:54","modified_gmt":"2024-12-02T04:14:54","slug":"go-%e7%bb%93%e6%9e%84%e4%bd%93%e5%ae%9a%e4%b9%89%ef%bc%9avar-%e5%92%8c-type-%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48566\/","title":{"rendered":"Go \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Go \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300aGo \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730084104671efd086d9a5.jpg\" class=\"aligncenter\" title=\"Go \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"Go \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>golang var \u548c type \u5e94\u7528\u4e8e\u7ed3\u6784\u7684\u533a\u522b<\/strong><\/p>\n<p>\u5bf9\u4e8e go \u7f16\u7a0b\u8bed\u8a00\u7684\u65b0\u624b\uff0c\u53ef\u80fd\u4f1a\u6ce8\u610f\u5230\u4e0d\u540c\u7684\u7ed3\u6784\u5b9a\u4e49\u65b9\u5f0f\uff0c\u5373\u4f7f\u7528 var \u548c type \u5173\u952e\u5b57\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u8bf4\u660e\u8fd9\u4e24\u79cd\u5199\u6cd5\u7684\u533a\u522b\u3002<\/p>\n<p><strong>\u533f\u540d\u7ed3\u6784<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 var \u5173\u952e\u5b57\u58f0\u660e\u7ed3\u6784\u65f6\uff0c\u5b9e\u9645\u4e0a\u662f\u5728\u521b\u5efa\u4e00\u4e2a <strong>\u533f\u540d\u7ed3\u6784<\/strong>\u3002\u533f\u540d\u7ed3\u6784\u6ca1\u6709\u663e\u5f0f\u58f0\u660e\u5176\u7c7b\u578b\uff0c\u800c\u662f\u4f7f\u7528\u5927\u62ec\u53f7\u76f4\u63a5\u5b9a\u4e49\u5176\u5b57\u6bb5\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>var people struct {\n    name string\n}<\/pre>\n<p>\u8fd9\u7b49\u540c\u4e8e\u58f0\u660e\u4e00\u4e2a\u540d\u4e3a people \u7684\u7c7b\u578b\uff0c\u7136\u540e\u4f7f\u7528\u8be5\u7c7b\u578b\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u53d8\u91cf people\uff1a<\/p>\n<pre>type people struct {\n    name string\n}\nvar people = people{}<\/pre>\n<p><strong>\u547d\u540d\u7ed3\u6784<\/strong><\/p>\n<p>\u53e6\u4e00\u65b9\u9762\uff0c\u4f7f\u7528 type \u5173\u952e\u5b57\u58f0\u660e\u7ed3\u6784\u65f6\uff0c\u5219\u662f\u521b\u5efa\u4e86\u4e00\u4e2a <strong>\u547d\u540d\u7ed3\u6784<\/strong>\u3002\u547d\u540d\u7ed3\u6784\u5177\u6709\u660e\u786e\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u5728\u4ee5\u540e\u7528\u4e8e\u58f0\u660e\u8be5\u7c7b\u578b\u7684\u5176\u4ed6\u53d8\u91cf\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>type people struct {\n    name string\n}<\/pre>\n<p>\u8fd9\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a people \u7684\u7ed3\u6784\u7c7b\u578b\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528\u8be5\u7c7b\u578b\u58f0\u660e\u5176\u4ed6\u53d8\u91cf\uff1a<\/p>\n<pre>var people1 people\nvar people2 people<\/pre>\n<p><strong>\u5173\u952e\u533a\u522b<\/strong><\/p>\n<p>\u533f\u540d\u7ed3\u6784\u548c\u547d\u540d\u7ed3\u6784\u4e4b\u95f4\u7684\u5173\u952e\u533a\u522b\u5728\u4e8e\uff1a<\/p>\n<ul>\n<li><strong>\u4f5c\u7528\u57df\uff1a<\/strong> \u533f\u540d\u7ed3\u6784\u4ec5\u5728\u58f0\u660e\u5b83\u7684\u5305\u4e2d\u6709\u6548\u3002\u547d\u540d\u7ed3\u6784\u53ef\u5728\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/li>\n<li><strong>\u53ef\u91cd\u7528\u6027\uff1a<\/strong> \u547d\u540d\u7ed3\u6784\u53ef\u4ee5\u88ab\u5176\u4ed6\u53d8\u91cf\u6216\u7c7b\u578b\u91cd\u7528\u3002\u533f\u540d\u7ed3\u6784\u53ea\u80fd\u7528\u4e8e\u521b\u5efa\u5b83\u6240\u5c5e\u7684\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n<ul>\n<li><strong>\u533f\u540d\u7ed3\u6784\uff1a<\/strong> \u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u6570\u636e\u6216\u521b\u5efa\u4e34\u65f6\u5bf9\u8c61\u65f6\u3002<\/li>\n<li><strong>\u547d\u540d\u7ed3\u6784\uff1a<\/strong> \u7528\u4e8e\u5b9a\u4e49\u53ef\u91cd\u7528\u7684\u6570\u636e\u7ed3\u6784\u6216\u8868\u793a\u7a0b\u5e8f\u4e2d\u7684\u5b9e\u4f53\u65f6\u3002<\/li>\n<\/ul>\n<p>\u603b\u4e4b\uff0cvar \u548c type \u5e94\u7528\u4e8e\u7ed3\u6784\u7684\u5199\u6cd5\u5728\u4f5c\u7528\u57df\u548c\u53ef\u91cd\u7528\u6027\u65b9\u9762\u5b58\u5728\u533a\u522b\u3002\u9009\u62e9\u9002\u5f53\u7684\u5199\u6cd5\u53d6\u51b3\u4e8e\u4f60\u8981\u8868\u8fbe\u7684\u6570\u636e\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u7ed3\u6784\u3002<\/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\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300aGo \u7ed3\u6784\u4f53\u5b9a\u4e49\uff1avar \u548c type \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 golang var \u548c type \u5e94\u7528\u4e8e\u7ed3\u6784\u7684\u533a\u522b \u5bf9\u4e8e go \u7f16\u7a0b\u8bed\u8a00\u7684\u65b0\u624b\uff0c\u53ef\u80fd\u4f1a\u6ce8\u610f\u5230\u4e0d\u540c\u7684\u7ed3\u6784\u5b9a\u4e49\u65b9\u5f0f\uff0c\u5373\u4f7f\u7528 var \u548c type \u5173\u952e\u5b57\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u8bf4\u660e\u8fd9\u4e24\u79cd\u5199\u6cd5\u7684\u533a\u522b\u3002 \u533f\u540d\u7ed3\u6784 \u5f53\u4f7f\u7528 var \u5173\u952e\u5b57\u58f0\u660e\u7ed3\u6784\u65f6\uff0c\u5b9e\u9645\u4e0a\u662f\u5728\u521b\u5efa\u4e00\u4e2a \u533f\u540d\u7ed3\u6784\u3002\u533f\u540d\u7ed3\u6784\u6ca1\u6709\u663e\u5f0f\u58f0\u660e\u5176\u7c7b\u578b\uff0c\u800c\u662f\u4f7f\u7528\u5927\u62ec\u53f7\u76f4\u63a5\u5b9a\u4e49\u5176\u5b57\u6bb5\u3002 \u793a\u4f8b\uff1a var people struct { name string } \u8fd9\u7b49\u540c\u4e8e\u58f0\u660e\u4e00\u4e2a\u540d\u4e3a people \u7684\u7c7b\u578b\uff0c\u7136\u540e\u4f7f\u7528\u8be5\u7c7b\u578b\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u53d8\u91cf people\uff1a type people struct { name string } var people = people{} \u547d\u540d\u7ed3\u6784 \u53e6\u4e00\u65b9\u9762\uff0c\u4f7f\u7528 type \u5173\u952e\u5b57\u58f0\u660e\u7ed3\u6784\u65f6\uff0c\u5219\u662f\u521b\u5efa\u4e86\u4e00\u4e2a \u547d\u540d\u7ed3\u6784\u3002\u547d\u540d\u7ed3\u6784\u5177\u6709\u660e\u786e\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u5728\u4ee5\u540e\u7528\u4e8e\u58f0\u660e\u8be5\u7c7b\u578b\u7684\u5176\u4ed6\u53d8\u91cf\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48566","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48566"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48566\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}