{"id":57654,"date":"2024-10-10T20:01:40","date_gmt":"2024-10-10T12:01:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57654\/"},"modified":"2024-10-10T20:01:40","modified_gmt":"2024-10-10T12:01:40","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e8%ae%8a%e9%87%8f%e7%9a%84%e7%94%9f%e5%91%bd%e9%80%b1%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57654\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e8%ae%8a%e9%87%8f%e7%9a%84%e7%94%9f%e5%91%bd%e9%80%b1%e6%9c%9f-DGiUsCRTBR\">GO\u6559\u7a0b: Go \u8a9e\u8a00\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f<\/h1>\n<p>\u5728\u5b78\u7fd2 Go \u8a9e\u8a00\u7684\u904e\u7a0b\u4e2d\uff0c\u7406\u89e3\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u6c7a\u5b9a\u4e86\u8b8a\u91cf\u5728\u7a0b\u5e8f\u57f7\u884c\u904e\u7a0b\u4e2d\u7684\u5b58\u5728\u6642\u9593\u548c\u53ef\u8a2a\u554f\u6027\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Go \u8a9e\u8a00\u4e2d\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\uff0c\u5305\u62ec\u8b8a\u91cf\u7684\u5b9a\u7fa9\u3001\u4f5c\u7528\u57df\u4ee5\u53ca\u5783\u573e\u56de\u6536\u6a5f\u5236\u3002<\/p>\n<h2 id=\"%e8%ae%8a%e9%87%8f%e7%9a%84%e5%ae%9a%e7%be%a9%e8%88%87%e5%88%9d%e5%a7%8b%e5%8c%96-DGiUsCRTBR\">\u8b8a\u91cf\u7684\u5b9a\u7fa9\u8207\u521d\u59cb\u5316<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u8b8a\u91cf\u53ef\u4ee5\u901a\u904e\u95dc\u9375\u5b57 <code>var<\/code> \u4f86\u5b9a\u7fa9\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u5b9a\u7fa9\u7684\u540c\u6642\u9032\u884c\u521d\u59cb\u5316\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>var x int = 10\nvar y = 20 \/\/ \u81ea\u52d5\u63a8\u65b7\u985e\u578b\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0cGo \u8a9e\u8a00\u9084\u652f\u6301\u77ed\u8b8a\u91cf\u8072\u660e\uff0c\u9019\u5728\u51fd\u6578\u5167\u90e8\u7279\u5225\u5e38\u7528\uff1a<\/p>\n<pre><code>x := 10\n<\/code><\/pre>\n<h2 id=\"%e8%ae%8a%e9%87%8f%e7%9a%84%e4%bd%9c%e7%94%a8%e5%9f%9f-DGiUsCRTBR\">\u8b8a\u91cf\u7684\u4f5c\u7528\u57df<\/h2>\n<p>\u8b8a\u91cf\u7684\u4f5c\u7528\u57df\u6c7a\u5b9a\u4e86\u8b8a\u91cf\u5728\u7a0b\u5e8f\u4e2d\u7684\u53ef\u898b\u6027\u3002Go \u8a9e\u8a00\u7684\u4f5c\u7528\u57df\u5206\u70ba\u5305\u7d1a\u4f5c\u7528\u57df\u548c\u51fd\u6578\u7d1a\u4f5c\u7528\u57df\uff1a<\/p>\n<ul>\n<li><strong>\u5305\u7d1a\u4f5c\u7528\u57df\uff1a<\/strong>\u5728\u5305\u5167\u90e8\u5b9a\u7fa9\u7684\u8b8a\u91cf\u53ef\u4ee5\u5728\u6574\u500b\u5305\u4e2d\u8a2a\u554f\u3002<\/li>\n<li><strong>\u51fd\u6578\u7d1a\u4f5c\u7528\u57df\uff1a<\/strong>\u5728\u51fd\u6578\u5167\u90e8\u5b9a\u7fa9\u7684\u8b8a\u91cf\u53ea\u80fd\u5728\u8a72\u51fd\u6578\u5167\u90e8\u8a2a\u554f\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>package main\n\nimport \"fmt\"\n\nvar globalVar = \"I am a global variable\"\n\nfunc main() {\n    localVar := \"I am a local variable\"\n    fmt.Println(globalVar) \/\/ \u53ef\u4ee5\u8a2a\u554f\n    fmt.Println(localVar)   \/\/ \u53ef\u4ee5\u8a2a\u554f\n}\n\nfunc anotherFunction() {\n    fmt.Println(globalVar) \/\/ \u53ef\u4ee5\u8a2a\u554f\n    \/\/ fmt.Println(localVar) \/\/ \u9019\u88e1\u6703\u5831\u932f\uff0c\u56e0\u70ba localVar \u4e0d\u5728\u4f5c\u7528\u57df\u5167\n}\n<\/code><\/pre>\n<h2 id=\"%e8%ae%8a%e9%87%8f%e7%9a%84%e7%94%9f%e5%91%bd%e9%80%b1%e6%9c%9f-DGiUsCRTBR\">\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f<\/h2>\n<p>\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u8207\u5176\u4f5c\u7528\u57df\u5bc6\u5207\u76f8\u95dc\u3002\u7576\u8b8a\u91cf\u88ab\u5275\u5efa\u6642\uff0c\u5b83\u7684\u751f\u547d\u9031\u671f\u958b\u59cb\uff0c\u7576\u8b8a\u91cf\u8d85\u51fa\u5176\u4f5c\u7528\u57df\u6642\uff0c\u5b83\u7684\u751f\u547d\u9031\u671f\u7d50\u675f\u3002Go \u8a9e\u8a00\u4f7f\u7528\u5783\u573e\u56de\u6536\u6a5f\u5236\u4f86\u7ba1\u7406\u5167\u5b58\uff0c\u9019\u610f\u5473\u8457\u4e0d\u518d\u4f7f\u7528\u7684\u8b8a\u91cf\u6703\u81ea\u52d5\u88ab\u6e05\u7406\u3002<\/p>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u53ef\u4ee5\u5206\u70ba\u4ee5\u4e0b\u5e7e\u500b\u968e\u6bb5\uff1a<\/p>\n<ul>\n<li><strong>\u5275\u5efa\uff1a<\/strong>\u7576\u8b8a\u91cf\u88ab\u5b9a\u7fa9\u4e26\u521d\u59cb\u5316\u6642\uff0c\u751f\u547d\u9031\u671f\u958b\u59cb\u3002<\/li>\n<li><strong>\u4f7f\u7528\uff1a<\/strong>\u5728\u5176\u4f5c\u7528\u57df\u5167\uff0c\u8b8a\u91cf\u53ef\u4ee5\u88ab\u8a2a\u554f\u548c\u4fee\u6539\u3002<\/li>\n<li><strong>\u7d50\u675f\uff1a<\/strong>\u7576\u8b8a\u91cf\u8d85\u51fa\u5176\u4f5c\u7528\u57df\uff0c\u6216\u8005\u7a0b\u5e8f\u7d50\u675f\u6642\uff0c\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u7d50\u675f\uff0c\u5167\u5b58\u6703\u88ab\u91cb\u653e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9e%83%e5%9c%be%e5%9b%9e%e6%94%b6%e6%a9%9f%e5%88%b6-DGiUsCRTBR\">\u5783\u573e\u56de\u6536\u6a5f\u5236<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u5783\u573e\u56de\u6536\u6a5f\u5236\u81ea\u52d5\u7ba1\u7406\u5167\u5b58\uff0c\u9019\u610f\u5473\u8457\u958b\u767c\u8005\u4e0d\u9700\u8981\u624b\u52d5\u91cb\u653e\u4e0d\u518d\u4f7f\u7528\u7684\u8b8a\u91cf\u3002\u9019\u4e00\u6a5f\u5236\u4f7f\u5f97 Go \u8a9e\u8a00\u5728\u8655\u7406\u8b8a\u91cf\u751f\u547d\u9031\u671f\u6642\u66f4\u52a0\u9ad8\u6548\u548c\u5b89\u5168\u3002<\/p>\n<p>\u5783\u573e\u56de\u6536\u7684\u5de5\u4f5c\u539f\u7406\u662f\u901a\u904e\u6a19\u8a18\u548c\u6e05\u9664\u4f86\u5be6\u73fe\u7684\u3002\u7576\u8b8a\u91cf\u4e0d\u518d\u88ab\u5f15\u7528\u6642\uff0c\u5783\u573e\u56de\u6536\u5668\u6703\u5c07\u5176\u6a19\u8a18\u70ba\u53ef\u56de\u6536\uff0c\u4e26\u5728\u9069\u7576\u7684\u6642\u5019\u91cb\u653e\u5176\u4f54\u7528\u7684\u5167\u5b58\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-DGiUsCRTBR\">\u7e3d\u7d50<\/h2>\n<p>\u7406\u89e3 Go \u8a9e\u8a00\u4e2d\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\u5c0d\u65bc\u7de8\u5beb\u9ad8\u6548\u548c\u5b89\u5168\u7684\u4ee3\u78bc\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u638c\u63e1\u8b8a\u91cf\u7684\u5b9a\u7fa9\u3001\u4f5c\u7528\u57df\u53ca\u5176\u751f\u547d\u9031\u671f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u5167\u5b58\uff0c\u907f\u514d\u6f5b\u5728\u7684\u5167\u5b58\u6cc4\u6f0f\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u904b\u884c\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u4e00\u500b\u91cd\u8981\u8003\u91cf\uff0c\u7279\u5225\u662f\u5728\u9999\u6e2f\u5730\u5340\uff0c<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u63d0\u4f9b\u4e86\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u64c7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 Go \u8a9e\u8a00\u4e2d\u8b8a\u91cf\u7684\u751f\u547d\u9031\u671f\uff0c\u638c\u63e1\u8b8a\u91cf\u7684\u4f5c\u7528\u57df\u3001\u521d\u59cb\u5316\u53ca\u92b7\u6bc0\u904e\u7a0b\uff0c\u63d0\u5347\u7de8\u7a0b\u6548\u7387\u8207\u4ee3\u78bc\u8cea\u91cf\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-57654","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57654","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=57654"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57654\/revisions"}],"predecessor-version":[{"id":57655,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57654\/revisions\/57655"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}