{"id":3842,"date":"2022-12-30T14:54:09","date_gmt":"2022-12-30T06:54:09","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3842"},"modified":"2022-12-30T14:54:09","modified_gmt":"2022-12-30T06:54:09","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e8%ae%8a%e9%87%8f%e9%a1%9e%e5%9e%8b%e8%bd%89%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e8%ae%8a%e9%87%8f%e9%a1%9e%e5%9e%8b%e8%bd%89%e5%9e%8b\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u4e2d\u7684\u8b8a\u91cf\u985e\u578b\u8f49\u578b"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, \u8b8a\u91cf\u985e\u578b\u8f49\u578b\"><\/p>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u5b83\u64c1\u6709\u5f37\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u9ad8\u6548\u7387\u7684\u61c9\u7528\u7a0b\u5e8f\u3002Go \u8a9e\u8a00\u4e2d\u6709\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\u5c31\u662f\u8b8a\u91cf\u985e\u578b\u8f49\u578b\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u4e00\u500b\u8b8a\u91cf\u7684\u985e\u578b\u5f9e\u4e00\u500b\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\uff0c\u4ee5\u6eff\u8db3\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u8b8a\u91cf\u985e\u578b\u8f49\u578b\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u4e00\u500b\u8b8a\u91cf\u7684\u985e\u578b\u5f9e\u4e00\u500b\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\uff0c\u4ee5\u6eff\u8db3\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002Go \u8a9e\u8a00\u652f\u6301\u591a\u7a2e\u8b8a\u91cf\u985e\u578b\u8f49\u578b\uff0c\u5305\u62ec\uff1a<strong>\u6574\u578b\u8f49\u63db<\/strong>\u3001<strong>\u6d6e\u9ede\u578b\u8f49\u63db<\/strong>\u3001<strong>\u5b57\u7b26\u4e32\u8f49\u63db<\/strong>\u3001<strong>\u5e03\u723e\u578b\u8f49\u63db<\/strong>\u7b49\u3002<\/p>\n<h2>\u6574\u578b\u8f49\u63db<\/h2>\n<p>\u6574\u578b\u8f49\u63db\u662f\u6307\u5c07\u4e00\u500b\u6574\u578b\u8b8a\u91cf\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u6574\u578b\u8b8a\u91cf\uff0c\u4f8b\u5982\u5c07 int32 \u8f49\u63db\u70ba int64\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u7f6e\u7684\u51fd\u6578 int64()\uff0c\u53ef\u4ee5\u5c07 int32 \u8f49\u63db\u70ba int64\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    var a int32 = 10\n    var b int64\n    b = int64(a)\n    fmt.Println(b)\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07 int32 \u8b8a\u91cf a \u8f49\u63db\u70ba int64 \u8b8a\u91cf b\uff0c\u8f38\u51fa\u7d50\u679c\u70ba 10\u3002<\/p>\n<h2>\u6d6e\u9ede\u578b\u8f49\u63db<\/h2>\n<p>\u6d6e\u9ede\u578b\u8f49\u63db\u662f\u6307\u5c07\u4e00\u500b\u6d6e\u9ede\u578b\u8b8a\u91cf\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u6d6e\u9ede\u578b\u8b8a\u91cf\uff0c\u4f8b\u5982\u5c07 float32 \u8f49\u63db\u70ba float64\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u7f6e\u7684\u51fd\u6578 float64()\uff0c\u53ef\u4ee5\u5c07 float32 \u8f49\u63db\u70ba float64\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    var a float32 = 10.5\n    var b float64\n    b = float64(a)\n    fmt.Println(b)\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07 float32 \u8b8a\u91cf a \u8f49\u63db\u70ba float64 \u8b8a\u91cf b\uff0c\u8f38\u51fa\u7d50\u679c\u70ba 10.5\u3002<\/p>\n<h2>\u5b57\u7b26\u4e32\u8f49\u63db<\/h2>\n<p>\u5b57\u7b26\u4e32\u8f49\u63db\u662f\u6307\u5c07\u4e00\u500b\u5b57\u7b26\u4e32\u8b8a\u91cf\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u5b57\u7b26\u4e32\u8b8a\u91cf\uff0c\u4f8b\u5982\u5c07 string \u8f49\u63db\u70ba []byte\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u7f6e\u7684\u51fd\u6578 []byte()\uff0c\u53ef\u4ee5\u5c07 string \u8f49\u63db\u70ba []byte\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    var a string = \"Hello World\"\n    var b []byte\n    b = []byte(a)\n    fmt.Println(b)\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07 string \u8b8a\u91cf a \u8f49\u63db\u70ba []byte \u8b8a\u91cf b\uff0c\u8f38\u51fa\u7d50\u679c\u70ba [72 101 108 108 111 32 87 111 114 108 100]\u3002<\/p>\n<h2>\u5e03\u723e\u578b\u8f49\u63db<\/h2>\n<p>\u5e03\u723e\u578b\u8f49\u63db\u662f\u6307\u5c07\u4e00\u500b\u5e03\u723e\u578b\u8b8a\u91cf\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u5e03\u723e\u578b\u8b8a\u91cf\uff0c\u4f8b\u5982\u5c07 bool \u8f49\u63db\u70ba int\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u7f6e\u7684\u51fd\u6578 int()\uff0c\u53ef\u4ee5\u5c07 bool \u8f49\u63db\u70ba int\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    var a bool = true\n    var b int\n    b = int(a)\n    fmt.Println(b)\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07 bool \u8b8a\u91cf a \u8f49\u63db\u70ba int \u8b8a\u91cf b\uff0c\u8f38\u51fa\u7d50\u679c\u70ba 1\u3002<\/p>\n<p>\u7e3d\u7d50\uff1aGo \u8a9e\u8a00\u4e2d\u7684\u8b8a\u91cf\u985e\u578b\u8f49\u578b\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u4e00\u500b\u8b8a\u91cf\u7684\u985e\u578b\u5f9e\u4e00\u500b\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\uff0c\u4ee5\u6eff\u8db3\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002Go \u8a9e\u8a00\u652f\u6301\u591a\u7a2e\u8b8a\u91cf\u985e\u578b\u8f49\u578b\uff0c\u5305\u62ec\uff1a\u6574\u578b\u8f49\u63db\u3001\u6d6e\u9ede\u578b\u8f49\u63db\u3001\u5b57\u7b26\u4e32\u8f49\u63db\u3001\u5e03\u723e\u578b\u8f49\u63db\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684\u8b8a\u91cf\u985e\u578b\u8f49\u578b\uff0c\u8a73\u7d30\u4ecb\u7d39\u4e86\u8b8a\u91cf\u985e\u578b\u8f49\u578b\u7684\u6982\u5ff5\u3001\u65b9\u6cd5\u3001\u512a\u9ede\u548c\u7f3a\u9ede\uff0c\u4e26\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\uff0c\u4ee5\u4fbf\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u8b8a\u91cf\u985e\u578b\u8f49\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-3842","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-ZY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3842","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=3842"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3842\/revisions"}],"predecessor-version":[{"id":3843,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3842\/revisions\/3843"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}