{"id":3760,"date":"2022-12-30T14:14:38","date_gmt":"2022-12-30T06:14:38","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3760"},"modified":"2022-12-30T14:14:38","modified_gmt":"2022-12-30T06:14:38","slug":"go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e9%ab%98%e7%b4%9a%e8%b3%87%e6%96%99%e9%a1%9e%e5%9e%8b%ef%bc%9a%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%e4%b8%a6%e6%8e%8c%e6%8f%a1","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e9%ab%98%e7%b4%9a%e8%b3%87%e6%96%99%e9%a1%9e%e5%9e%8b%ef%bc%9a%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%e4%b8%a6%e6%8e%8c%e6%8f%a1\/","title":{"rendered":"Go\u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff1a\u6df1\u5165\u4e86\u89e3\u4e26\u638c\u63e1"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, \u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\"><\/p>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u64c1\u6709\u8a31\u591a\u5f37\u5927\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39 Go \u8a9e\u8a00\u4e2d\u7684\u4e00\u4e9b\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u4e26\u8a73\u7d30\u8aaa\u660e\u5b83\u5011\u7684\u529f\u80fd\u548c\u7528\u6cd5\u3002<\/p>\n<h2>Go \u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b<\/h2>\n<p>Go \u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\u5305\u62ec\uff1a<strong>\u5207\u7247<\/strong>\u3001<strong>\u6620\u5c04<\/strong>\u3001<strong>\u7d50\u69cb<\/strong>\u548c<strong>\u63a5\u53e3<\/strong>\u3002<\/p>\n<h2>\u5207\u7247<\/h2>\n<p>\u5207\u7247\u662f Go \u8a9e\u8a00\u4e2d\u6700\u5e38\u7528\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4e00\u7cfb\u5217\u7684\u5143\u7d20\uff0c\u4e26\u4e14\u53ef\u4ee5\u52a8\u614b\u5730\u589e\u52a0\u6216\u6e1b\u5c11\u5143\u7d20\u7684\u6578\u91cf\u3002\u5207\u7247\u7684\u5ba3\u544a\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\nvar slice1 []int\n<\/pre>\n<p>\u5207\u7247\u53ef\u4ee5\u4f7f\u7528 append() \u51fd\u5f0f\u4f86\u52a8\u614b\u5730\u589e\u52a0\u5143\u7d20\uff1a<\/p>\n<pre class=\"brush: go\">\nslice1 = append(slice1, 1)\n<\/pre>\n<p><!--more--><\/p>\n<h2>\u6620\u5c04<\/h2>\n<p>\u6620\u5c04\u662f Go \u8a9e\u8a00\u4e2d\u53e6\u4e00\u500b\u5e38\u7528\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u9375\u503c\u5c0d\uff0c\u4e26\u4e14\u53ef\u4ee5\u52a8\u614b\u5730\u589e\u52a0\u6216\u6e1b\u5c11\u9375\u503c\u5c0d\u7684\u6578\u91cf\u3002\u6620\u5c04\u7684\u5ba3\u544a\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\nvar map1 map[string]int\n<\/pre>\n<p>\u6620\u5c04\u53ef\u4ee5\u4f7f\u7528 make() \u51fd\u5f0f\u4f86\u52a8\u614b\u5730\u589e\u52a0\u9375\u503c\u5c0d\uff1a<\/p>\n<pre class=\"brush: go\">\nmap1 = make(map[string]int)\nmap1[\"key1\"] = 1\n<\/pre>\n<h2>\u7d50\u69cb<\/h2>\n<p>\u7d50\u69cb\u662f Go \u8a9e\u8a00\u4e2d\u53e6\u4e00\u500b\u5e38\u7528\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4e00\u7cfb\u5217\u7684\u8cc7\u6599\uff0c\u4e26\u4e14\u53ef\u4ee5\u52a8\u614b\u5730\u589e\u52a0\u6216\u6e1b\u5c11\u8cc7\u6599\u7684\u6578\u91cf\u3002\u7d50\u69cb\u7684\u5ba3\u544a\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\ntype Person struct {\n    Name string\n    Age  int\n}\n<\/pre>\n<p>\u7d50\u69cb\u53ef\u4ee5\u4f7f\u7528 new() \u51fd\u5f0f\u4f86\u52a8\u614b\u5730\u589e\u52a0\u8cc7\u6599\uff1a<\/p>\n<pre class=\"brush: go\">\nperson1 := new(Person)\nperson1.Name = \"John\"\nperson1.Age = 20\n<\/pre>\n<h2>\u63a5\u53e3<\/h2>\n<p>\u63a5\u53e3\u662f Go \u8a9e\u8a00\u4e2d\u53e6\u4e00\u500b\u5e38\u7528\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u4e00\u7cfb\u5217\u7684\u65b9\u6cd5\uff0c\u4e26\u4e14\u53ef\u4ee5\u52a8\u614b\u5730\u589e\u52a0\u6216\u6e1b\u5c11\u65b9\u6cd5\u7684\u6578\u91cf\u3002\u63a5\u53e3\u7684\u5ba3\u544a\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\ntype Animal interface {\n    Move()\n    Eat()\n}\n<\/pre>\n<p>\u63a5\u53e3\u53ef\u4ee5\u4f7f\u7528\u5ba3\u544a\u4f86\u52a8\u614b\u5730\u589e\u52a0\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: go\">\nfunc (a *Animal) Sleep() {\n    \/\/ Sleep logic\n}\n<\/pre>\n<p>\u7e3d\u7d50<\/p>\n<p>Go \u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u672c\u6587\u4ecb\u7d39\u4e86 Go \u8a9e\u8a00\u4e2d\u7684\u4e00\u4e9b\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u4e26\u8a73\u7d30\u8aaa\u660e\u5b83\u5011\u7684\u529f\u80fd\u548c\u7528\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u7ba1\u7406\u8cc7\u6599\uff0c\u672c\u6587\u5c07\u6df1\u5165\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684\u9ad8\u7d1a\u8cc7\u6599\u985e\u578b\uff0c\u5305\u62ec\u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7d44\u7b49\uff0c\u8b93\u958b\u767c\u8005\u66f4\u52a0\u719f\u6089\u4e26\u638c\u63e1\u9019\u4e9b\u8cc7\u6599\u985e\u578b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[171,172],"tags":[169,170],"class_list":["post-3760","post","type-post","status-publish","format-standard","hentry","category-go","category-golang","tag-go","tag-golang"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-YE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3760"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3760\/revisions"}],"predecessor-version":[{"id":3761,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3760\/revisions\/3761"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}