{"id":43,"date":"2026-03-30T18:47:18","date_gmt":"2026-03-30T10:47:18","guid":{"rendered":"http:\/\/peishop.cn\/?p=43"},"modified":"2026-03-30T18:47:18","modified_gmt":"2026-03-30T10:47:18","slug":"go%e8%af%ad%e8%a8%80%e5%b8%b8%e7%94%a8%e5%86%85%e7%bd%ae%e5%8c%85","status":"publish","type":"post","link":"https:\/\/peishop.cn\/index.php\/2026\/03\/30\/go%e8%af%ad%e8%a8%80%e5%b8%b8%e7%94%a8%e5%86%85%e7%bd%ae%e5%8c%85\/","title":{"rendered":"Go\u8bed\u8a00\u5e38\u7528\u5185\u7f6e\u5305"},"content":{"rendered":"\n<p>\u6807\u51c6\u7684Go\u8bed\u8a00\u4ee3\u7801\u5e93\u4e2d\u5305\u542b\u4e86\u5927\u91cf\u7684\u5305\uff0c\u5e76\u4e14\u5728\u5b89\u88c5 Go \u7684\u65f6\u5019\u591a\u6570\u4f1a\u81ea\u52a8\u5b89\u88c5\u5230\u7cfb\u7edf\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u5728 $GOROOT\/src\/pkg \u76ee\u5f55\u4e2d\u67e5\u770b\u8fd9\u4e9b\u5305\u3002\u4e0b\u9762\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e9b\u6211\u4eec\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u5305\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">1) fmt<\/p>\n\n\n\n<p>fmt \u5305\u5b9e\u73b0\u4e86\u683c\u5f0f\u5316\u7684\u6807\u51c6\u8f93\u5165\u8f93\u51fa\uff0c\u8fd9\u4e0eC\u8bed\u8a00\u4e2d\u7684 printf \u548c scanf \u7c7b\u4f3c\u3002\u5176\u4e2d\u7684 fmt.Printf() \u548c fmt.Println() \u662f\u5f00\u53d1\u8005\u4f7f\u7528\u6700\u4e3a\u9891\u7e41\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u683c\u5f0f\u5316\u77ed\u8bed\u6d3e\u751f\u4e8eC\u8bed\u8a00\uff0c\u4e00\u4e9b\u77ed\u8bed\uff08%- \u5e8f\u5217\uff09\u662f\u8fd9\u6837\u4f7f\u7528\uff1a%v\uff1a\u9ed8\u8ba4\u683c\u5f0f\u7684\u503c\u3002\u5f53\u6253\u5370\u7ed3\u6784\u65f6\uff0c\u52a0\u53f7\uff08%+v\uff09\u4f1a\u589e\u52a0\u5b57\u6bb5\u540d\uff1b<\/p>\n\n\n\n<p>%#v\uff1aGo\u6837\u5f0f\u7684\u503c\u8868\u8fbe\uff1b<\/p>\n\n\n\n<p>%T\uff1a\u5e26\u6709\u7c7b\u578b\u7684 Go \u6837\u5f0f\u7684\u503c\u8868\u8fbe\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">2) io<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u5305\u63d0\u4f9b\u4e86\u539f\u59cb\u7684 I\/O \u64cd\u4f5c\u754c\u9762\u3002\u5b83\u4e3b\u8981\u7684\u4efb\u52a1\u662f\u5bf9 os \u5305\u8fd9\u6837\u7684\u539f\u59cb\u7684 I\/O \u8fdb\u884c\u5c01\u88c5\uff0c\u589e\u52a0\u4e00\u4e9b\u5176\u4ed6\u76f8\u5173\uff0c\u4f7f\u5176\u5177\u6709\u62bd\u8c61\u529f\u80fd\u7528\u5728\u516c\u5171\u7684\u63a5\u53e3\u4e0a\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">3) bufio<\/p>\n\n\n\n<p>bufio \u5305\u901a\u8fc7\u5bf9 io \u5305\u7684\u5c01\u88c5\uff0c\u63d0\u4f9b\u4e86\u6570\u636e\u7f13\u51b2\u529f\u80fd\uff0c\u80fd\u591f\u4e00\u5b9a\u7a0b\u5ea6\u51cf\u5c11\u5927\u5757\u6570\u636e\u8bfb\u5199\u5e26\u6765\u7684\u5f00\u9500\u3002<\/p>\n\n\n\n<p>\u5728 bufio \u5404\u4e2a\u7ec4\u4ef6\u5185\u90e8\u90fd\u7ef4\u62a4\u4e86\u4e00\u4e2a\u7f13\u51b2\u533a\uff0c\u6570\u636e\u8bfb\u5199\u64cd\u4f5c\u90fd\u76f4\u63a5\u901a\u8fc7\u7f13\u5b58\u533a\u8fdb\u884c\u3002\u5f53\u53d1\u8d77\u4e00\u6b21\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u4f1a\u9996\u5148\u5c1d\u8bd5\u4ece\u7f13\u51b2\u533a\u83b7\u53d6\u6570\u636e\uff0c\u53ea\u6709\u5f53\u7f13\u51b2\u533a\u6ca1\u6709\u6570\u636e\u65f6\uff0c\u624d\u4f1a\u4ece\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\u66f4\u65b0\u7f13\u51b2\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">4) sort<\/p>\n\n\n\n<p>sort \u5305\u63d0\u4f9b\u4e86\u7528\u4e8e\u5bf9\u5207\u7247\u548c\u7528\u6237\u5b9a\u4e49\u7684\u96c6\u5408\u8fdb\u884c\u6392\u5e8f\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">5) strconv<\/p>\n\n\n\n<p>strconv \u5305\u63d0\u4f9b\u4e86\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u6216\u8005\u4ece\u57fa\u672c\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">6) os<\/p>\n\n\n\n<p>os \u5305\u63d0\u4f9b\u4e86\u4e0d\u4f9d\u8d56\u5e73\u53f0\u7684\u64cd\u4f5c\u7cfb\u7edf\u51fd\u6570\u63a5\u53e3\uff0c\u8bbe\u8ba1\u50cf Unix \u98ce\u683c\uff0c\u4f46\u9519\u8bef\u5904\u7406\u662f go \u98ce\u683c\uff0c\u5f53 os \u5305\u4f7f\u7528\u65f6\uff0c\u5982\u679c\u5931\u8d25\u540e\u8fd4\u56de\u9519\u8bef\u7c7b\u578b\u800c\u4e0d\u662f\u9519\u8bef\u6570\u91cf\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">7) sync<\/p>\n\n\n\n<p>sync \u5305\u5b9e\u73b0\u591a\u7ebf\u7a0b\u4e2d\u9501\u673a\u5236\u4ee5\u53ca\u5176\u4ed6\u540c\u6b65\u4e92\u65a5\u673a\u5236\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">8) flag<\/p>\n\n\n\n<p>flag \u5305\u63d0\u4f9b\u547d\u4ee4\u884c\u53c2\u6570\u7684\u89c4\u5219\u5b9a\u4e49\u548c\u4f20\u5165\u53c2\u6570\u89e3\u6790\u7684\u529f\u80fd\u3002\u7edd\u5927\u90e8\u5206\u7684\u547d\u4ee4\u884c\u7a0b\u5e8f\u90fd\u9700\u8981\u7528\u5230\u8fd9\u4e2a\u5305\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">9) encoding\/json<\/p>\n\n\n\n<p>JSON \u76ee\u524d\u5e7f\u6cdb\u7528\u505a\u7f51\u7edc\u7a0b\u5e8f\u4e2d\u7684\u901a\u4fe1\u683c\u5f0f\u3002encoding\/json \u5305\u63d0\u4f9b\u4e86\u5bf9 JSON \u7684\u57fa\u672c\u652f\u6301\uff0c\u6bd4\u5982\u4ece\u4e00\u4e2a\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u5b57\u7b26\u4e32\uff0c\u6216\u8005\u4ece JSON \u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u51fa\u4e00\u4e2a\u5177\u4f53\u7684\u5bf9\u8c61\u7b49\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">10) html\/template<\/p>\n\n\n\n<p>\u4e3b\u8981\u5b9e\u73b0\u4e86 web \u5f00\u53d1\u4e2d\u751f\u6210 html \u7684 template \u7684\u4e00\u4e9b\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">11) net\/http<\/p>\n\n\n\n<p>net\/http \u5305\u63d0\u4f9b HTTP \u76f8\u5173\u670d\u52a1\uff0c\u4e3b\u8981\u5305\u62ec http \u8bf7\u6c42\u3001\u54cd\u5e94\u548c URL \u7684\u89e3\u6790\uff0c\u4ee5\u53ca\u57fa\u672c\u7684 http \u5ba2\u6237\u7aef\u548c\u6269\u5c55\u7684 http \u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7 net\/http \u5305\uff0c\u53ea\u9700\u8981\u6570\u884c\u4ee3\u7801\uff0c\u5373\u53ef\u5b9e\u73b0\u4e00\u4e2a\u722c\u866b\u6216\u8005\u4e00\u4e2a Web \u670d\u52a1\u5668\uff0c\u8fd9\u5728\u4f20\u7edf\u8bed\u8a00\u4e2d\u662f\u65e0\u6cd5\u60f3\u8c61\u7684\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">12) reflect<\/p>\n\n\n\n<p>reflect \u5305\u5b9e\u73b0\u4e86\u8fd0\u884c\u65f6\u53cd\u5c04\uff0c\u5141\u8bb8\u7a0b\u5e8f\u901a\u8fc7\u62bd\u8c61\u7c7b\u578b\u64cd\u4f5c\u5bf9\u8c61\u3002\u901a\u5e38\u7528\u4e8e\u5904\u7406\u9759\u6001\u7c7b\u578b interface{} \u7684\u503c\uff0c\u5e76\u4e14\u901a\u8fc7 Typeof \u89e3\u6790\u51fa\u5176\u52a8\u6001\u7c7b\u578b\u4fe1\u606f\uff0c\u901a\u5e38\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6709\u63a5\u53e3\u7c7b\u578b Type \u7684\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">13) os\/exec<\/p>\n\n\n\n<p>os\/exec \u5305\u63d0\u4f9b\u4e86\u6267\u884c\u81ea\u5b9a\u4e49 linux \u547d\u4ee4\u7684\u76f8\u5173\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">14) strings<\/p>\n\n\n\n<p>strings \u5305\u4e3b\u8981\u662f\u5904\u7406\u5b57\u7b26\u4e32\u7684\u4e00\u4e9b\u51fd\u6570\u96c6\u5408\uff0c\u5305\u62ec\u5408\u5e76\u3001\u67e5\u627e\u3001\u5206\u5272\u3001\u6bd4\u8f83\u3001\u540e\u7f00\u68c0\u67e5\u3001\u7d22\u5f15\u3001\u5927\u5c0f\u5199\u5904\u7406\u7b49\u7b49\u3002<\/p>\n\n\n\n<p>strings \u5305\u4e0e bytes \u5305\u7684\u51fd\u6570\u63a5\u53e3\u529f\u80fd\u57fa\u672c\u4e00\u81f4\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">15) bytes<\/p>\n\n\n\n<p>bytes \u5305\u63d0\u4f9b\u4e86\u5bf9\u5b57\u8282\u5207\u7247\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u7684\u4e00\u7cfb\u5217\u51fd\u6570\u3002\u5b57\u8282\u5207\u7247\u5904\u7406\u7684\u51fd\u6570\u6bd4\u8f83\u591a\uff0c\u5206\u4e3a\u57fa\u672c\u5904\u7406\u51fd\u6570\u3001\u6bd4\u8f83\u51fd\u6570\u3001\u540e\u7f00\u68c0\u67e5\u51fd\u6570\u3001\u7d22\u5f15\u51fd\u6570\u3001\u5206\u5272\u51fd\u6570\u3001\u5927\u5c0f\u5199\u5904\u7406\u51fd\u6570\u548c\u5b50\u5207\u7247\u5904\u7406\u51fd\u6570\u7b49\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size\">16) log<\/p>\n\n\n\n<p>log \u5305\u4e3b\u8981\u7528\u4e8e\u5728\u7a0b\u5e8f\u4e2d\u8f93\u51fa\u65e5\u5fd7\u3002<\/p>\n\n\n\n<p>log \u5305\u4e2d\u63d0\u4f9b\u4e86\u4e09\u7c7b\u65e5\u5fd7\u8f93\u51fa\u63a5\u53e3\uff0cPrint\u3001Fatal \u548c Panic\u3002Print \u662f\u666e\u901a\u8f93\u51fa\uff1b<\/p>\n\n\n\n<p>Fatal \u662f\u5728\u6267\u884c\u5b8c Print \u540e\uff0c\u6267\u884c os.Exit(1)\uff1b<\/p>\n\n\n\n<p>Panic \u662f\u5728\u6267\u884c\u5b8c Print \u540e\u8c03\u7528 panic() \u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6807\u51c6\u7684Go\u8bed\u8a00\u4ee3\u7801\u5e93\u4e2d\u5305\u542b\u4e86\u5927\u91cf\u7684\u5305\uff0c\u5e76\u4e14\u5728\u5b89\u88c5 Go \u7684\u65f6\u5019\u591a\u6570\u4f1a\u81ea\u52a8\u5b89\u88c5\u5230\u7cfb\u7edf\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u5728 $GOROO [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/posts\/43"}],"collection":[{"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":1,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions\/44"}],"wp:attachment":[{"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peishop.cn\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}