{"id":3676,"date":"2022-12-30T13:27:58","date_gmt":"2022-12-30T05:27:58","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3676"},"modified":"2022-12-30T13:27:58","modified_gmt":"2022-12-30T05:27:58","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e5%9f%ba%e7%a4%8e%e8%aa%9e%e6%b3%95%ef%bc%8c%e6%8e%8c%e6%8f%a1%e7%a8%8b%e5%bc%8f%e9%96%8b%e7%99%bc%e7%9a%84%e5%9f%ba%e7%a4%8e","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e5%9f%ba%e7%a4%8e%e8%aa%9e%e6%b3%95%ef%bc%8c%e6%8e%8c%e6%8f%a1%e7%a8%8b%e5%bc%8f%e9%96%8b%e7%99%bc%e7%9a%84%e5%9f%ba%e7%a4%8e\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u57fa\u790e\u8a9e\u6cd5\uff0c\u638c\u63e1\u7a0b\u5f0f\u958b\u767c\u7684\u57fa\u790e"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, Go\u8a9e\u8a00, Go\u8a9e\u8a00\u57fa\u790e\u8a9e\u6cd5\"><\/p>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u5b83\u7684\u57fa\u790e\u8a9e\u6cd5\u975e\u5e38\u7c21\u55ae\u6613\u5b78\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u4e0a\u624b\u3002\u672c\u6587\u5c07\u4ecb\u7d39 Go \u8a9e\u8a00\u7684\u57fa\u790e\u8a9e\u6cd5\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1 Go \u8a9e\u8a00\u7684\u57fa\u790e\u77e5\u8b58\u3002<\/p>\n<h2>Go \u8a9e\u8a00\u7684\u57fa\u790e\u8a9e\u6cd5<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u57fa\u790e\u8a9e\u6cd5\u5305\u62ec\u8b8a\u6578\u5ba3\u544a\u3001\u689d\u4ef6\u5224\u65b7\u3001\u8ff4\u5708\u3001\u51fd\u6578\u3001\u985e\u5225\u7b49\u7b49\u3002<\/p>\n<h2>\u8b8a\u6578\u5ba3\u544a<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u8b8a\u6578\u5ba3\u544a\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">var<\/span> \u95dc\u9375\u5b57\u5373\u53ef\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: go\">var a int\nvar b string\nvar c bool\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5ba3\u544a\u4e09\u500b\u8b8a\u6578\uff0c\u5206\u5225\u662f\u6574\u6578\u578b\u614b\u7684 a\u3001\u5b57\u4e32\u578b\u614b\u7684 b\u3001\u5e03\u6797\u578b\u614b\u7684 c\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u689d\u4ef6\u5224\u65b7<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u689d\u4ef6\u5224\u65b7\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">if<\/span> \u95dc\u9375\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: go\">if a == 1 {\n    \/\/ do something\n} else if a == 2 {\n    \/\/ do something\n} else {\n    \/\/ do something\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5224\u65b7 a \u7684\u503c\uff0c\u5982\u679c a \u7b49\u65bc 1\uff0c\u5247\u57f7\u884c\u7b2c\u4e00\u500b\u5224\u65b7\uff1b\u5982\u679c a \u7b49\u65bc 2\uff0c\u5247\u57f7\u884c\u7b2c\u4e8c\u500b\u5224\u65b7\uff1b\u5982\u679c\u90fd\u4e0d\u7b26\u5408\uff0c\u5247\u57f7\u884c\u7b2c\u4e09\u500b\u5224\u65b7\u3002<\/p>\n<h2>\u8ff4\u5708<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u8ff4\u5708\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">for<\/span> \u95dc\u9375\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: go\">for i := 0; i < 10; i++ {\n    \/\/ do something\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u57f7\u884c 10 \u6b21\u8ff4\u5708\uff0c\u6bcf\u6b21\u8ff4\u5708\u6703\u5c07 i \u7684\u503c\u52a0 1\u3002<\/p>\n<h2>\u51fd\u6578<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u51fd\u6578\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">func<\/span> \u95dc\u9375\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: go\">func add(a int, b int) int {\n    return a + b\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5ba3\u544a\u4e00\u500b\u51fd\u6578\uff0c\u540d\u7a31\u70ba add\uff0c\u5b83\u6703\u63a5\u6536\u5169\u500b\u53c3\u6578\uff0c\u4e26\u4e14\u6703\u50b3\u56de\u5169\u500b\u53c3\u6578\u7684\u548c\u3002<\/p>\n<h2>\u985e\u5225<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u985e\u5225\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">type<\/span> \u95dc\u9375\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: go\">type Person struct {\n    Name string\n    Age  int\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5ba3\u544a\u4e00\u500b\u985e\u5225\uff0c\u540d\u7a31\u70ba Person\uff0c\u5b83\u6703\u6709\u5169\u500b\u5c6c\u6027\uff0c\u5206\u5225\u662f Name \u548c Age\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 Go \u8a9e\u8a00\u7684\u57fa\u790e\u8a9e\u6cd5\uff0c\u5305\u62ec\u8b8a\u6578\u5ba3\u544a\u3001\u689d\u4ef6\u5224\u65b7\u3001\u8ff4\u5708\u3001\u51fd\u6578\u3001\u985e\u5225\u7b49\u7b49\u3002\u958b\u767c\u8005\u53ef\u4ee5\u501f\u52a9\u9019\u4e9b\u57fa\u790e\u8a9e\u6cd5\u4f86\u5feb\u901f\u638c\u63e1 Go \u8a9e\u8a00\uff0c\u4e26\u4e14\u958b\u767c\u51fa\u9ad8\u6548\u7387\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aGo\u8a9e\u8a00\u662f\u4e00\u7a2e\u7c21\u55ae\u6613\u5b78\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u7684\u57fa\u790e\u8a9e\u6cd5\uff0c\u5305\u62ec\u8b8a\u6578\u5ba3\u544a\u3001\u8cc7\u6599\u578b\u614b\u3001\u689d\u4ef6\u5224\u65b7\u3001\u8ff4\u5708\u3001\u51fd\u6578\u7b49\uff0c\u8b93\u4f60\u5feb\u901f\u638c\u63e1\u7a0b\u5f0f\u958b\u767c\u7684\u57fa\u790e\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-3676","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-Xi","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3676","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=3676"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3676\/revisions"}],"predecessor-version":[{"id":3677,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3676\/revisions\/3677"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}