{"id":57742,"date":"2024-10-10T20:47:10","date_gmt":"2024-10-10T12:47:10","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57742\/"},"modified":"2024-10-10T20:47:10","modified_gmt":"2024-10-10T12:47:10","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57742\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00\u6578\u64da\u985e\u578b\u8f49\u63db"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b-CgMpdRgtAr\">GO\u6559\u7a0b: Go \u8a9e\u8a00\u6578\u64da\u985e\u578b\u8f49\u63db<\/h1>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u6578\u64da\u985e\u578b\u8f49\u63db\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u56e0\u70ba\u5b83\u5141\u8a31\u958b\u767c\u8005\u5728\u4e0d\u540c\u7684\u6578\u64da\u985e\u578b\u4e4b\u9593\u9032\u884c\u9748\u6d3b\u7684\u64cd\u4f5c\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u63a2\u8a0e Go \u8a9e\u8a00\u4e2d\u7684\u6578\u64da\u985e\u578b\u8f49\u63db\uff0c\u5305\u62ec\u57fa\u672c\u7684\u8f49\u63db\u65b9\u6cd5\u3001\u6ce8\u610f\u4e8b\u9805\u4ee5\u53ca\u5be6\u969b\u7684\u4ee3\u78bc\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-CgMpdRgtAr\">\u57fa\u672c\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5728\u958b\u59cb\u6578\u64da\u985e\u578b\u8f49\u63db\u4e4b\u524d\uff0c\u6211\u5011\u9700\u8981\u4e86\u89e3 Go \u8a9e\u8a00\u4e2d\u7684\u57fa\u672c\u6578\u64da\u985e\u578b\u3002Go \u8a9e\u8a00\u4e3b\u8981\u6709\u4ee5\u4e0b\u5e7e\u7a2e\u57fa\u672c\u6578\u64da\u985e\u578b\uff1a<\/p>\n<ul>\n<li><code>int<\/code>\uff1a\u6574\u6578\u985e\u578b\uff0c\u6839\u64da\u5e73\u53f0\u7684\u4e0d\u540c\uff0c\u5927\u5c0f\u53ef\u80fd\u70ba 32 \u4f4d\u6216 64 \u4f4d\u3002<\/li>\n<li><code>float64<\/code>\uff1a\u96d9\u7cbe\u5ea6\u6d6e\u9ede\u6578\u3002<\/li>\n<li><code>string<\/code>\uff1a\u5b57\u7b26\u4e32\u985e\u578b\u3002<\/li>\n<li><code>bool<\/code>\uff1a\u5e03\u723e\u985e\u578b\uff0c\u53ea\u6709 <code>true<\/code> \u548c <code>false<\/code> \u5169\u500b\u503c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%96%b9%e6%b3%95-CgMpdRgtAr\">\u6578\u64da\u985e\u578b\u8f49\u63db\u7684\u57fa\u672c\u65b9\u6cd5<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u6578\u64da\u985e\u578b\u8f49\u63db\u7684\u8a9e\u6cd5\u76f8\u5c0d\u7c21\u55ae\u3002\u57fa\u672c\u7684\u8f49\u63db\u65b9\u6cd5\u662f\u4f7f\u7528\u62ec\u865f\u4f86\u6307\u5b9a\u76ee\u6a19\u985e\u578b\u3002\u4f8b\u5982\uff0c\u5c07\u4e00\u500b\u6574\u6578\u8f49\u63db\u70ba\u6d6e\u9ede\u6578\uff0c\u53ef\u4ee5\u9019\u6a23\u5beb\uff1a<\/p>\n<pre><code>var a int = 10\nvar b float64 = float64(a)\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u5c07\u6574\u6578 <code>a<\/code> \u8f49\u63db\u70ba\u6d6e\u9ede\u6578\u4e26\u8ce6\u503c\u7d66 <code>b<\/code>\u3002\u9019\u7a2e\u8f49\u63db\u662f\u5b89\u5168\u7684\uff0c\u56e0\u70ba\u6574\u6578\u53ef\u4ee5\u7121\u640d\u5730\u8f49\u63db\u70ba\u6d6e\u9ede\u6578\u3002<\/p>\n<h2 id=\"%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%88%87%e6%95%b8%e5%ad%97%e4%b9%8b%e9%96%93%e7%9a%84%e8%bd%89%e6%8f%9b-CgMpdRgtAr\">\u5b57\u7b26\u4e32\u8207\u6578\u5b57\u4e4b\u9593\u7684\u8f49\u63db<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u5b57\u7b26\u4e32\u548c\u6578\u5b57\u4e4b\u9593\u7684\u8f49\u63db\u7a0d\u5fae\u8907\u96dc\u4e00\u4e9b\u3002\u8981\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6574\u6578\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>strconv<\/code> \u5305\u4e2d\u7684 <code>.Atoi<\/code> \u51fd\u6578\uff1a<\/p>\n<pre><code>import \"strconv\"\n\nvar str string = \"123\"\nvar num int\nvar err error\n\nnum, err = strconv.Atoi(str)\nif err != nil {\n    \/\/ \u8655\u7406\u932f\u8aa4\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u5c07\u5b57\u7b26\u4e32 <code>str<\/code> \u8f49\u63db\u70ba\u6574\u6578 <code>num<\/code>\u3002\u5982\u679c\u8f49\u63db\u5931\u6557\uff0c<code>err<\/code> \u5c07\u5305\u542b\u932f\u8aa4\u4fe1\u606f\u3002<\/p>\n<p>\u76f8\u53cd\uff0c\u5c07\u6574\u6578\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u53ef\u4ee5\u4f7f\u7528 <code>strconv.Itoa<\/code> \u51fd\u6578\uff1a<\/p>\n<pre><code>var num int = 123\nvar str string = strconv.Itoa(num)\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-CgMpdRgtAr\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u985e\u578b\u8f49\u63db\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li>\u8f49\u63db\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u3002\u4f8b\u5982\uff0c\u5c07\u6d6e\u9ede\u6578\u8f49\u63db\u70ba\u6574\u6578\u6642\uff0c\u5c0f\u6578\u90e8\u5206\u5c07\u88ab\u622a\u65b7\u3002<\/li>\n<li>\u5728\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6578\u5b57\u6642\uff0c\u5fc5\u9808\u78ba\u4fdd\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u6b63\u78ba\uff0c\u5426\u5247\u6703\u7522\u751f\u932f\u8aa4\u3002<\/li>\n<li>Go \u8a9e\u8a00\u662f\u975c\u614b\u985e\u578b\u8a9e\u8a00\uff0c\u9019\u610f\u5473\u8457\u5728\u7de8\u8b6f\u6642\u5fc5\u9808\u660e\u78ba\u6307\u5b9a\u6578\u64da\u985e\u578b\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-CgMpdRgtAr\">\u7d50\u8ad6<\/h2>\n<p>\u6578\u64da\u985e\u578b\u8f49\u63db\u5728 Go \u8a9e\u8a00\u4e2d\u662f\u4e00\u500b\u57fa\u672c\u800c\u91cd\u8981\u7684\u64cd\u4f5c\u3002\u901a\u904e\u6b63\u78ba\u5730\u4f7f\u7528\u8f49\u63db\u65b9\u6cd5\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u9748\u6d3b\u5730\u8655\u7406\u4e0d\u540c\u985e\u578b\u7684\u6578\u64da\u3002\u5728\u5be6\u969b\u958b\u767c\u4e2d\uff0c\u7406\u89e3\u9019\u4e9b\u8f49\u63db\u7684\u539f\u7406\u548c\u6ce8\u610f\u4e8b\u9805\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u4ee3\u78bc\u7684\u8cea\u91cf\u548c\u53ef\u8b80\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u6216\u5176\u4ed6\u76f8\u95dc\u670d\u52d9\u611f\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Go\u8a9e\u8a00\u4e2d\u7684\u6578\u64da\u985e\u578b\u8f49\u63db\uff0c\u638c\u63e1\u57fa\u672c\u8a9e\u6cd5\u548c\u5be6\u7528\u7bc4\u4f8b\uff0c\u63d0\u5347\u7de8\u7a0b\u6280\u80fd\uff0c\u8f15\u9b06\u8655\u7406\u6578\u64da\u985e\u578b\u554f\u984c\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-57742","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57742","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=57742"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57742\/revisions"}],"predecessor-version":[{"id":57743,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57742\/revisions\/57743"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}