{"id":208310,"date":"2025-07-08T13:56:10","date_gmt":"2025-07-08T05:56:10","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208310\/"},"modified":"2025-07-08T13:56:10","modified_gmt":"2025-07-08T05:56:10","slug":"golang-%e6%96%87%e5%ad%97%e5%92%8c%e5%b8%b8%e9%87%8f%e4%b9%8b%e9%97%b4%e7%9a%84%e6%80%a7%e8%83%bd%e5%b7%ae%e5%bc%82","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208310\/","title":{"rendered":"Golang &#8211; \u6587\u5b57\u548c\u5e38\u91cf\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02"},"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>Golang &#8211; \u6587\u5b57\u548c\u5e38\u91cf\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-05-01 16:27: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>\u5c0f\u4f19\u4f34\u4eec\u5bf9Golang\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aGolang &#8211; \u6587\u5b57\u548c\u5e38\u91cf\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u4e3b\u8981\u5c06\u5e38\u91cf\u7528\u4e8e\u6587\u6863\u76ee\u7684\uff0c\u4f8b\u5982\u4e00\u4e2a\u6709\u7528\u7684\u53d8\u91cf\u540d\uff0c\u6216\u8005\u5f53\u6211\u4e00\u904d\u53c8\u4e00\u904d\u5730\u91cd\u590d\u67d0\u4e9b\u5b57\u7b26\u4e32\u5e8f\u5217\u5e76\u4e14\u4e0d\u60f3\u624b\u52a8\u66f4\u6539\u5b83\u4eec\u65f6\u3002\u4f46\u6211\u60f3\u77e5\u9053\u662f\u5426\u6709\u4efb\u4f55\u6027\u80fd\u5dee\u5f02\u3002\u6211\u7684\u5047\u8bbe\u662f\u5426\u6b63\u786e\uff0c\u5373\u6587\u5b57\u548c\u5e38\u91cf\u4e4b\u95f4\u6ca1\u6709\u8fd0\u884c\u65f6\u5dee\u5f02\uff0c\u56e0\u4e3a\u5e38\u91cf\u662f\u5728\u8fd0\u884c\u65f6\u66ff\u6362\u7684\uff1f<\/p>\n<p>\u4e5f\u8bb8\u6211\u8bef\u89e3\u4e86\uff0c\u4f46\u6211\u6ca1\u6709\u53d1\u73b0\u4efb\u4f55\u4e1c\u897f\u544a\u8bc9\u6211\u8fd9\u662f\u9519\u8bef\u7684\u3002 Go Tour \u6ca1\u6709\u63d0\u4f9b\u4efb\u4f55\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff0cConstants \u535a\u5ba2\u6587\u7ae0\u4e5f\u6ca1\u6709\u63d0\u4f9b\u4efb\u4f55\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u5373\u4f7f\u662f\u8fd9\u4e2a\u5fae\u4e0d\u8db3\u9053\u7684\u7a0b\u5e8f\uff0c\u4e5f\u6ca1\u6709\u4efb\u4f55\u8bf4\u660e\uff1a<\/p>\n<pre>package main\nfunc main() {}<\/pre>\n<p>\u5728\u5468\u4e8c\u7f16\u8bd1\u65f6\u53ef\u80fd\u4f1a\u50cf\u95ea\u7535\u4e00\u6837\u5feb\uff0c\u4f46\u5728\u5468\u4e94\u4e0b\u5348\u665a\u4e9b\u65f6\u5019\u7f16\u8bd1\u65f6\u4f1a\u50cf\u7cd6\u871c\u4e00\u6837\u6162\u3002 \uff08\u4e5f\u8bb8 go \u7f16\u8bd1\u5668\u6025\u4e8e\u56de\u5bb6\u559d\u676f\u5564\u9152\u5e76\u5ea6\u8fc7\u4e00\u4e2a\u5468\u672b\uff0c\u5e76\u5728\u5468\u4e94\u4e0b\u5348\u751f\u6210\u4e86\u7cdf\u7cd5\u7684\u4ee3\u7801\u3002<sup>1<\/sup>\uff09<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u60a8\u8981\u8fdb\u884c\u6bd4\u8f83\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n)\nconst hello = \"hello\"\nvar playground = \"playground\"\n\nfunc main() {\n    fmt.printf(\"%s, %s\\n\", hello, playground)\n}\n<\/pre>\n<p>\u6211\u4eec\u53ef\u80fd\u4f1a\u6ce8\u610f\u5230\uff0c\u5728 <code>const<\/code> \u53d8\u4f53 (<code>hello<\/code>) \u4e2d\uff0c\u7f16\u8bd1\u5668<em>\u88ab\u8feb<\/em>\u5728\u7f16\u8bd1\u65f6\u77e5\u9053\u5b57\u7b26\u4e32\u6587\u5b57 <code>\"hello\"<\/code> \u662f\u5b57\u7b26\u4e32\u6587\u5b57\uff0c\u800c\u5728 <code>var<\/code> \u53d8\u4f53\u4e2d\uff08<code>\u6f14\u793a<\/code>\uff09\uff0c\u7f16\u8bd1\u5668<em>\u53ef\u80fd<\/em>\u5f88\u61d2\uff0c\u5047\u8bbe\u53d8\u91cf<code>\u6f14\u793a<\/code>\u53ef\u80fd\u5728\u5176\u4ed6\u51fd\u6570\u4e2d\u88ab\u4fee\u6539\u3002\u53cd\u8fc7\u6765\uff0c\u7ed3\u5408\u7f16\u8bd1\u5668\u77e5\u9053 <code>fmt.println<\/code> \u662f\u4e00\u4e2a<em>\u7279\u5b9a<\/em>\u51fd\u6570\u7684\u80fd\u529b\uff08\u4f8b\u5982 gcc \u63d2\u5165 c <code>printf<\/code> \u51fd\u6570\u7684\u7279\u6b8a\u77e5\u8bc6\u7684\u65b9\u5f0f\uff09<em>\u53ef\u4ee5<\/em> em&gt; \u5141\u8bb8\u7f16\u8bd1\u5668\u66f4\u8f7b\u677e\u5730\u5c06\u5176\u7f16\u8bd1\u4e3a\uff1a<\/p>\n<pre>fmt.Printf(\"hello, %s\\n\", playground)<\/pre>\n<p>\u5176\u4e2d\u53ea\u6709\u4e00\u4e2a\u8fd0\u884c\u65f6 <code>reflect<\/code> \u53d1\u751f\uff0c\u4ee5\u9632\u53d8\u91cf <code> \u6f14\u793a <\/code> \u5df2\u66f4\u6539\u3002\u4f46\u662f\u73b0\u6709\u7684 go \u7f16\u8bd1\u5668\u4f7f\u7528 \uff08\u53e6\u8bf7\u53c2\u9605 \uff09\u5e76\u4e14\u6ca1\u6709\u5bf9\u8be5\u53d8\u91cf\u8fdb\u884c\u5199\u5165\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u671f\u5f85\u7b80\u5355\uff08\u901a\u5e38\u7b80\u5355 = \u5feb\u901f\uff09\u7684\u8fd0\u884c\u65f6\u4ee3\u7801\u3002<\/p>\n<p>\u73a9\u5f04\uff0c\u4f3c\u4e4e\u5728\u4f7f\u7528<code>const<\/code>\u65f6\uff0c\u5f53\u524d\u7f16\u8bd1\u5668\u5b9e\u9645\u4e0a\u5fc5\u987b\u63d2\u5165\u4e00\u4e2a\u5230\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u3002 <code>var<\/code> \u7248\u672c\u7684\u8fd0\u884c\u65f6\u4ee3\u7801\u66f4\u5c11\u3002\u6211\u6ca1\u6709\u7528\u63d2\u5165\u7684\u5b57\u7b26\u4e32\u6587\u5b57\u6765\u6d4b\u8bd5\u5b83\u3002 <code>%s<\/code> \u6307\u4ee4\u6c38\u8fdc\u4e0d\u4f1a\u5728\u7ebf\u6269\u5c55\uff0c\u4f46 <code>fmt.printf<\/code> \u5b9e\u9645\u4e0a\u76f4\u63a5\u8c03\u7528 <code>fmt.fprintf<\/code>\uff0c\u5e76\u4ee5 <code>os.stdout<\/code> \u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u60a8\u901a\u5e38\u6700\u597d\u5c3d\u53ef\u80fd\u7f16\u5199<em>\u6700\u6e05\u6670<\/em>\u7684\u4ee3\u7801\u3002\u7136\u540e\uff0c\u5982\u679c\u901f\u5ea6\u592a\u6162\uff08\u65e0\u8bba\u60a8\u5bf9\u201c\u592a\u6162\u201d\u7684\u5b9a\u4e49\u5982\u4f55\uff09\uff0c\u8bf7\u8fdb\u884c\u6d4b\u91cf\u3002\u4e0d\u8fc7\uff0c\u6211\u5bf9\u81ea\u5df1\u7684\u7f16\u7801\u65f6\u95f4\u4f18\u5316\u8fc7\u5ea6\u611f\u5230\u5185\u759a\u3002 \ud83d\ude42<\/p>\n<p><sup>1<\/sup><\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aGolang &#8211; \u6587\u5b57\u548c\u5e38\u91cf\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\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-208310","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208310","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=208310"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208310\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}