{"id":57724,"date":"2024-10-10T20:39:36","date_gmt":"2024-10-10T12:39:36","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57724\/"},"modified":"2024-10-10T20:39:36","modified_gmt":"2024-10-10T12:39:36","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e6%95%b4%e5%9e%8b%ef%bc%88%e6%95%b4%e6%95%b8%e9%a1%9e%e5%9e%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57724\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00\u6574\u578b\uff08\u6574\u6578\u985e\u578b\uff09"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e6%95%b4%e5%9e%8b%ef%bc%88%e6%95%b4%e6%95%b8%e9%a1%9e%e5%9e%8b%ef%bc%89-dwvQYkrIyE\">GO\u6559\u7a0b: Go \u8a9e\u8a00\u6574\u578b\uff08\u6574\u6578\u985e\u578b\uff09<\/h1>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975c\u614b\u985e\u578b\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u5177\u6709\u7c21\u6f54\u7684\u8a9e\u6cd5\u548c\u9ad8\u6548\u7684\u6027\u80fd\u3002\u6574\u578b\uff08\u6574\u6578\u985e\u578b\uff09\u662f Go \u8a9e\u8a00\u4e2d\u6700\u57fa\u672c\u7684\u6578\u64da\u985e\u578b\u4e4b\u4e00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u8a08\u7b97\u548c\u6578\u64da\u8655\u7406\u4e2d\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Go \u8a9e\u8a00\u4e2d\u7684\u6574\u578b\uff0c\u5305\u62ec\u5176\u985e\u578b\u3001\u7bc4\u570d\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e6%95%b4%e5%9e%8b%e7%9a%84%e9%a1%9e%e5%9e%8b-dwvQYkrIyE\">\u6574\u578b\u7684\u985e\u578b<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u6574\u578b\u4e3b\u8981\u5206\u70ba\u4ee5\u4e0b\u5e7e\u7a2e\u985e\u578b\uff1a<\/p>\n<ul>\n<li><code>int<\/code>: \u5e73\u53f0\u76f8\u95dc\u7684\u6574\u6578\u985e\u578b\uff0c\u901a\u5e38\u70ba 32 \u4f4d\u6216 64 \u4f4d\u3002<\/li>\n<li><code>int8<\/code>: 8 \u4f4d\u6709\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba -128 \u5230 127\u3002<\/li>\n<li><code>int16<\/code>: 16 \u4f4d\u6709\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba -32,768 \u5230 32,767\u3002<\/li>\n<li><code>int32<\/code>: 32 \u4f4d\u6709\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba -2,147,483,648 \u5230 2,147,483,647\u3002<\/li>\n<li><code>int64<\/code>: 64 \u4f4d\u6709\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba -9,223,372,036,854,775,808 \u5230 9,223,372,036,854,775,807\u3002<\/li>\n<li><code>uint<\/code>: \u7121\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u8207 <code>int<\/code> \u76f8\u540c\u3002<\/li>\n<li><code>uint8<\/code>: 8 \u4f4d\u7121\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba 0 \u5230 255\u3002<\/li>\n<li><code>uint16<\/code>: 16 \u4f4d\u7121\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba 0 \u5230 65,535\u3002<\/li>\n<li><code>uint32<\/code>: 32 \u4f4d\u7121\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba 0 \u5230 4,294,967,295\u3002<\/li>\n<li><code>uint64<\/code>: 64 \u4f4d\u7121\u7b26\u865f\u6574\u6578\uff0c\u7bc4\u570d\u70ba 0 \u5230 18,446,744,073,709,551,615\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b4%e5%9e%8b%e7%9a%84%e4%bd%bf%e7%94%a8-dwvQYkrIyE\">\u6574\u578b\u7684\u4f7f\u7528<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u6574\u578b\u7684\u4f7f\u7528\u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    var a int = 10\n    var b int32 = 20\n    var c int64 = 30\n\n    fmt.Println(\"\u6574\u6578 a:\", a)\n    fmt.Println(\"\u6574\u6578 b:\", b)\n    fmt.Println(\"\u6574\u6578 c:\", c)\n\n    \/\/ \u6574\u6578\u904b\u7b97\n    sum := a + int(b) + int(c)\n    fmt.Println(\"\u7e3d\u548c:\", sum)\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e09\u500b\u6574\u6578\u8b8a\u91cf\uff0c\u4e26\u9032\u884c\u4e86\u7c21\u55ae\u7684\u52a0\u6cd5\u904b\u7b97\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7576\u9032\u884c\u4e0d\u540c\u985e\u578b\u7684\u6574\u6578\u904b\u7b97\u6642\uff0c\u5fc5\u9808\u9032\u884c\u985e\u578b\u8f49\u63db\u3002<\/p>\n<h2 id=\"%e6%95%b4%e5%9e%8b%e7%9a%84%e7%89%b9%e6%80%a7-dwvQYkrIyE\">\u6574\u578b\u7684\u7279\u6027<\/h2>\n<p>Go \u8a9e\u8a00\u4e2d\u7684\u6574\u578b\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u975c\u614b\u985e\u578b:<\/strong> \u6574\u578b\u5728\u7de8\u8b6f\u6642\u5c31\u5df2\u78ba\u5b9a\uff0c\u9019\u6709\u52a9\u65bc\u63d0\u9ad8\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u81ea\u52d5\u5783\u573e\u56de\u6536:<\/strong> Go \u8a9e\u8a00\u81ea\u5e36\u7684\u5783\u573e\u56de\u6536\u6a5f\u5236\u80fd\u5920\u81ea\u52d5\u7ba1\u7406\u5167\u5b58\uff0c\u6e1b\u5c11\u5167\u5b58\u6cc4\u6f0f\u7684\u98a8\u96aa\u3002<\/li>\n<li><strong>\u652f\u6301\u5927\u6578\u64da:<\/strong> \u4f7f\u7528 <code>int64<\/code> \u548c <code>uint64<\/code> \u53ef\u4ee5\u8655\u7406\u975e\u5e38\u5927\u7684\u6574\u6578\uff0c\u9069\u5408\u9700\u8981\u9ad8\u7cbe\u5ea6\u8a08\u7b97\u7684\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-dwvQYkrIyE\">\u7d50\u8ad6<\/h2>\n<p>\u6574\u578b\u662f Go \u8a9e\u8a00\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u6578\u64da\u985e\u578b\uff0c\u4e86\u89e3\u5176\u7279\u6027\u548c\u4f7f\u7528\u65b9\u6cd5\u5c0d\u65bc\u958b\u767c\u9ad8\u6548\u7684\u61c9\u7528\u7a0b\u5e8f\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f\u9032\u884c\u57fa\u672c\u7684\u6578\u5b78\u904b\u7b97\u9084\u662f\u8655\u7406\u8907\u96dc\u7684\u6578\u64da\u7d50\u69cb\uff0c\u6574\u578b\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u4f3a\u670d\u5668\u7684\u9078\u64c7\u6709\u8208\u8da3\uff0c\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u53ef\u4ee5\u5728\u6211\u5011\u7684\u7db2\u7ad9\u4e0a\u627e\u5230\u66f4\u591a\u8cc7\u8a0a\u3002\u4e86\u89e3\u5982\u4f55\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a>\uff0c\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Go \u8a9e\u8a00\u4e2d\u7684\u6574\u578b\uff08\u6574\u6578\u985e\u578b\uff09\uff0c\u4e86\u89e3\u5176\u5b9a\u7fa9\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u7bc4\u4f8b\uff0c\u52a9\u4f60\u8f15\u9b06\u638c\u63e1\u6578\u64da\u8655\u7406\u6280\u5de7\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-57724","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57724","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=57724"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57724\/revisions"}],"predecessor-version":[{"id":57725,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57724\/revisions\/57725"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}