{"id":239159,"date":"2022-04-10T10:08:21","date_gmt":"2022-04-10T02:08:21","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=239159"},"modified":"2022-03-29T12:08:58","modified_gmt":"2022-03-29T04:08:58","slug":"go-fure-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/go-fure-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdGo \u4e2d\u7684\u7a7a\u767d\u6807\u8bc6\u7b26\u4e0b\u5212\u7ebf"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Go \u4e2d\u7684\u7a7a\u767d\u6807\u8bc6\u7b26\u4e0b\u5212\u7ebf\uff0c\u7a7a\u767d\u6807\u8bc6\u7b26\u662f\u672a\u4f7f\u7528\u7684\u503c\u7684\u5360\u4f4d\u7b26\uff0c\u7531\u4e0b\u5212\u7ebf\uff08_\uff09\u8868\u793a\uff0c\u4e0b\u6587\u5bf9\u5176\u76f8\u5173\u4ecb\u7ecd\u9700\u8981\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4e0e Python \u4e00\u6837\uff0cGo \u8bed\u8a00\u4e5f\u6709\u7a7a\u767d\u6807\u8bc6\u7b26\u3002<\/p>\n

1.\u4ec0\u4e48\u662f\u7a7a\u767d\u6807\u8bc6\u7b26<\/strong><\/div>\n

\u7a7a\u767d\u6807\u8bc6\u7b26\u662f\u672a\u4f7f\u7528\u7684\u503c\u7684\u5360\u4f4d\u7b26\u3002\u5b83\u7531\u4e0b\u5212\u7ebf\uff08_\uff09\u8868\u793a\u3002\u7531\u4e8e\u7a7a\u767d\u6807\u8bc6\u7b26\u6ca1\u6709\u540d\u79f0\uff0c\u56e0\u6b64\u5b83\u4eec\u4e5f\u88ab\u79f0\u4e3a\u533f\u540d\u5360\u4f4d\u7b26\u3002<\/p>\n

\u5728 Go \u8bed\u8a00\u4e2d\uff0c \u4e0d\u5141\u8bb8\u58f0\u660e\u672a\u4f7f\u7528\u7684\u53d8\u91cf\u6216\u5bfc\u5165\u8bed\u53e5\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u65e0\u6cd5\u58f0\u660e\u53d8\u91cf\u5e76\u5c06\u5176\u7559\u4e0b\u672a\u4f7f\u7528\u3002\u540c\u6837\uff0c\u5982\u679c\u60a8\u5bfc\u5165\u4e00\u4e2a\u5305\uff0c\u90a3\u4e48\u4e5f\u5fc5\u987b\u4f7f\u7528\u5b83\u3002<\/p>\n

\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u4e00\u4e2a\u7a7a\u767d\u6807\u8bc6\u7b26\u3002<\/p>\n

2.\u672a\u4f7f\u7528\u7684\u8d4b\u503c\u53d8\u91cf<\/strong><\/div>\n

\u5982\u679c Go \u4e2d\u7684\u51fd\u6570\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u5219\u5fc5\u987b\u5b9a\u4e49\u76f8\u7b49\u6570\u91cf\u7684\u53d8\u91cf\u6765\u4fdd\u5b58\u8fd9\u4e9b\u503c\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u53ea\u9700\u8981\u5176\u4e2d\u4e00\u4e9b\u503c\u800c\u4e0d\u9700\u8981\u5176\u4ed6\u503c\uff0c\u82e5\u67d0\u6b21\u8d4b\u503c\u9700\u8981\u5339\u914d\u591a\u4e2a\u5de6\u503c\uff0c\u4f46\u5176\u4e2d\u67d0\u4e2a\u53d8\u91cf\u4e0d\u4f1a\u88ab\u7a0b\u5e8f\u4f7f\u7528\uff0c \u90a3\u4e48\u7528\u7a7a\u767d\u6807\u8bc6\u7b26\u6765\u4ee3\u66ff\u3002\u8be5\u53d8\u91cf\u53ef\u907f\u514d\u521b\u5efa\u65e0\u7528\u7684\u53d8\u91cf\uff0c\u5e76\u80fd\u6e05\u695a\u5730\u8868\u660e\u8be5\u503c\u5c06\u88ab\u4e22\u5f03\u3002<\/p>\n

\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

result, error = Dosomething()\r\nif error {\r\n\/\/ handle error\r\n}<\/pre>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u200b\u200bresult\u200b\u200b \u4e0e\u7a0b\u5e8f\u65e0\u5173\uff0c\u800c\u4e14\u540e\u7eed\u4ee3\u7801\u4e5f\u6ca1\u6709\u4f7f\u7528\u5b83\u3002\u5982\u679c\u7f16\u8bd1\u7684\u8bdd\uff0cGo \u7f16\u8bd1\u5668\u4f1a\u62a5\u9519\u3002<\/p>\n

result declared but not used<\/pre>\n

\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u5c06\u7ed3\u679c\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf\u6216\u7a7a\u767d\u6807\u8bc6\u7b26\uff0c<\/p>\n

\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

_, error = Dosomething()\r\nif error {\r\n\/\/ handle error\r\n}<\/pre>\n

\u5373\u4f7f\u60a8\u58f0\u660e\u4e86\u4e00\u4e2a\u53d8\u91cf\uff0c\u60a8\u4e5f\u53ef\u4ee5\u7a0d\u540e\u4f7f\u7528\u7a7a\u767d\u6807\u8bc6\u7b26\u6765\u5ffd\u7565\u5b83\uff0c\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u6240\u793a\uff1a<\/p>\n

product, error = Dosomething()\r\nif error {\r\n\/\/ handle error\r\n}\r\n\/\/ ignore unused variable\r\n_ = product<\/pre>\n

\u5728 \u200b\u200bfor...range\u200b\u200b \u4e2d\u4f7f\u7528\u7a7a\u767d\u6807\u5fd7\u7b26<\/p>\n

func Sum(numbers []int) int {\r\n \r\nsum := 0\r\nfor _, number := range numbers {\r\nsum += number\r\n}\r\nreturn sum\r\n}<\/pre>\n
3.\u672a\u77e5\u7684\u7ed3\u6784\u4f53<\/strong><\/div>\n

\u53ef\u4ee5\u5229\u7528 \u200b\u200b_\u200b\u200b \u5206\u914d\u4efb\u4f55\u4e1c\u897f:<\/p>\n

var _ I = T{}<\/pre>\n

\u65e0\u6cd5\u8bbf\u95ee\u6b64\u53d8\u91cf\uff0c\u4ee5\u4fbf\u5c06\u4ece\u751f\u6210\u7684\u7a0b\u5e8f\u4e2d\u4f18\u5316\u3002\u4f46\u662f\uff0c\u5982\u679c T \u7c7b\u578b\u672a\u5206\u914d\u7ed9\u63a5\u53e3 \u200b\u200bI\u200b\u200b \uff0c\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u88ab\u7528\u4f5c\u5173\u4e8e\u7c7b\u578b\u7684\u9759\u6001\u65ad\u8a00\u3002<\/p>\n

4.\u672a\u4f7f\u7528\u7684\u5305<\/strong><\/div>\n

\u5728 Go \u4e2d\uff0c\u5982\u679c\u4f60\u5bfc\u5165\u4e00\u4e2a\u5305\uff0c\u90a3\u4e48\u4f60\u5fc5\u987b\u4f7f\u7528\u5b83\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u7f16\u8bd1\u5668\u9519\u8bef\u3002<\/p>\n

imported and not used \u201c\u201d<\/package><\/pre>\n

\u7a7a\u767d\u6807\u8bc6\u7b26\u53ef\u7528\u4e8e\u89e3\u51b3\u6b64\u7f16\u8bd1\u5668\u9519\u8bef\u3002<\/p>\n

\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528\u7a7a\u767d\u6807\u8bc6\u7b26\u6765\u89e3\u51b3\u672a\u4f7f\u7528\u7684\u5305\u9519\u8bef\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n

\u7b2c\u4e00\u79cd\uff1a\u58f0\u660e\u4e00\u4e2a\u5168\u5c40\u7a7a\u767d\u6807\u8bc6\u7b26\uff08\u5728 \u200b\u200bmain()\u200b\u200b \u51fd\u6570\u4e4b\u524d\uff09\uff0c\u8be5\u6807\u8bc6\u7b26\u4ece\u672a\u4f7f\u7528\u7684\u5305\u4e2d\u8bbf\u95ee\u7b26\u53f7\uff0c\u4f8b\u5982\u4e0b\u9762\u4ee3\u7801\u4e2d\u7684 Open\uff1a<\/p>\n

import \"os\"\r\nvar _ = os.Open\r\nfunc main() {\r\n}<\/pre>\n

\u7b2c\u4e8c\u79cd\uff1a\u5728\u672a\u4f7f\u7528\u7684\u5305\u524d\u52a0\u4e0a\u4e00\u4e2a\u7a7a\u767d\u6807\u8bc6\u7b26\uff0c<\/p>\n

\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

import _ \"os\"\r\n \r\nfunc main(){\r\n}<\/pre>\n

\u7a7a\u767d\u6807\u8bc6\u7b26\u901a\u8fc7\u907f\u514d\u5728\u6574\u4e2a\u4ee3\u7801\u4e2d\u4f7f\u7528\u672a\u4f7f\u7528\u7684\u53d8\u91cf\u58f0\u660e\uff0c\u4f7f\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\u3002<\/p>\n

5.\u603b\u7ed3<\/strong><\/div>\n

Golang \u4e2d\u4efb\u4f55\u58f0\u660e\u4f46\u672a\u4f7f\u7528\u7684\u5305\u548c\u53d8\u91cf\u90fd\u4f1a\u5f15\u53d1\u9519\u8bef\u3002\u8fd9\u4e00\u89c4\u5219\u4f7f\u5f97\u6211\u4eec\u7684\u4ee3\u7801\u4fdd\u6301\u5e72\u51c0\u548c\u8f7b\u91cf\u3002<\/p>\n

\u6709\u65f6\u5982\u679c\u9700\u8981\u5728\u672a\u6765\u4f7f\u7528\u5e76\u63d0\u524d\u5bfc\u5165\u4e00\u4e9b\u8f6f\u4ef6\u5305\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u7a7a\u767d\u6807\u8bc6\u7b26\u3002<\/p>\n

\u6709\u65f6\u5019\u51fd\u6570\u4f1a\u8fd4\u56de\u591a\u4e2a\u53c2\u6570\uff0c\u4f46\u662f\u6211\u4eec\u53ea\u9700\u8981\u4f7f\u7528\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u7a7a\u767d\u6807\u5fd7\u7b26\u6765\u8fdb\u884c\u63a5\u6536\u3002<\/p>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eGo \u4e2d\u7684\u7a7a\u767d\u6807\u8bc6\u7b26\u4e0b\u5212\u7ebf\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e0e Python \u4e00\u6837\uff0cGo \u8bed\u8a00\u4e5f\u6709\u7a7a\u767d\u6807\u8bc6\u7b26\u3002 \u7a7a\u767d\u6807\u8bc6\u7b26\u662f\u672a\u4f7f\u7528\u7684\u503c\u7684\u5360\u4f4d\u7b26\u3002\u5b83\u7531\u4e0b\u5212\u7ebf\uff08_\uff09\u8868\u793a\u3002\u7531\u4e8e […]<\/p>\n","protected":false},"author":668,"featured_media":216259,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-239159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=239159"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239159\/revisions"}],"predecessor-version":[{"id":239162,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239159\/revisions\/239162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/216259"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=239159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=239159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=239159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}