{"id":249263,"date":"2022-09-13T10:04:27","date_gmt":"2022-09-13T02:04:27","guid":{"rendered":"https:\/\/gulass.cn\/?p=249263"},"modified":"2022-09-05T04:50:41","modified_gmt":"2022-09-04T20:50:41","slug":"go-statement-avoidance","status":"publish","type":"post","link":"https:\/\/gulass.cn\/go-statement-avoidance.html","title":{"rendered":"Go \u8bed\u8a00\u77ed\u53d8\u91cf\u58f0\u660e\u907f\u5751\u6307\u5357"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u4f7f\u7528 Go \u8bed\u8a00\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u5728\u5b9a\u4e49\u53d8\u91cf\u65f6\u4f7f\u7528 Go \u8bed\u8a00\u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6 - \u77ed\u53d8\u91cf\u58f0\u660e\uff0c\u5b83\u867d\u7136\u597d\u7528\uff0c\u4f46\u662f\u4e5f\u4f1a\u6709\u8ba9\u6211\u4eec\u4e0d\u5c0f\u5fc3\u5c31\u4f1a\u6389\u8fdb\u7684\u201c\u5751\u201d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1.\u4ecb\u7ecd<\/strong><\/div>\n

\u5728\u4f7f\u7528 Go \u8bed\u8a00\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u5728\u5b9a\u4e49\u53d8\u91cf\u65f6\u4f7f\u7528 Go \u8bed\u8a00\u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6 - \u77ed\u53d8\u91cf\u58f0\u660e\uff0c\u5b83\u867d\u7136\u597d\u7528\uff0c\u4f46\u662f\u4e5f\u4f1a\u6709\u8ba9\u6211\u4eec\u4e0d\u5c0f\u5fc3\u5c31\u4f1a\u6389\u8fdb\u7684\u201c\u5751\u201d\u3002
\n\"\"
\n\u672c\u6587\u6211\u4eec\u4ecb\u7ecd\u4e00\u4e2a Go \u8bed\u8a00\u77ed\u53d8\u91cf\u58f0\u660e\u6700\u5bb9\u6613\u8ba9\u7a0b\u5e8f\u5458\u6389\u8fdb\u7684\u201c\u5751\u201d\u3002<\/p>\n

2.\u77ed\u53d8\u91cf\u58f0\u660e\u7684\u201c\u5751\u201d<\/strong><\/div>\n

Go \u8bed\u8a00\u63d0\u4f9b\u4e86\u77ed\u53d8\u91cf\u58f0\u660e\u7684\u8bed\u6cd5\u7cd6\uff0c\u77ed\u53d8\u91cf\u58f0\u660e\u8ba9 Go \u8bed\u8a00\u7684\u53d8\u91cf\u58f0\u660e\u66f4\u52a0\u65b9\u4fbf\uff0c\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u3002\u4f46\u662f\uff0c\u5b83\u771f\u7684\u767e\u5229\u65e0\u4e00\u5bb3\u5417\uff1f<\/p>\n

\u6211\u4eec\u5148\u9605\u8bfb\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n

func main() {\r\n var name string = \"frank\"\r\n fmt.Printf(\"val:%s || ptr:%p\\n\", name, &name)\r\n name, age := \"lucy\", 18\r\n fmt.Printf(\"val:%s || ptr:%p\\n\", name, &name)\r\n fmt.Println(age)\r\n if name != \"lily\" {\r\n  name := \"lily\"\r\n  fmt.Printf(\"val:%s || ptr:%p\\n\", name, &name)\r\n }\r\n}\r\n<\/pre>\n

\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n

val:frank || ptr:0xc000010200\r\nval:lucy || ptr:0xc000010200\r\n18\r\nval:lily || ptr:0xc000010230\r\n<\/pre>\n

\u9605\u8bfb\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4eec\u5148\u4f7f\u7528\u901a\u7528\u7684 Go \u8bed\u8a00\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\u58f0\u660e\u53d8\u91cf name\u200b\uff0c\u7136\u540e\u518d\u4f7f\u7528 Go \u8bed\u8a00\u8bed\u6cd5\u7cd6 - \u77ed\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\uff0c\u5206\u522b\u5728\u540c\u4e00\u4f5c\u7528\u57df\u548c\u4e0d\u540c\u4f5c\u7528\u57df\u58f0\u660e\u53d8\u91cf name\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u5ffd\u7565\u5728\u540c\u4e00\u4f5c\u7528\u57df\u4f7f\u7528\u77ed\u53d8\u91cf\u58f0\u660e\u65f6\u7684\u53d8\u91cf age\uff0c\u4ec5\u662f\u4e3a\u4e86\u8df3\u8fc7 Go \u7f16\u8bd1\u5668\u7684\u68c0\u67e5\u3002<\/p>\n

\u6839\u636e\u4e09\u6b21\u58f0\u660e\u53d8\u91cf name\u200b \u7684\u6253\u5370\u7ed3\u679c\u53ef\u4ee5\u770b\u51fa\uff0c\u4f7f\u7528\u77ed\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\u5728\u540c\u4e00\u4f5c\u7528\u57df\u58f0\u660e\u53d8\u91cf name\u200b\uff0c\u4ec5\u662f\u5bf9\u53d8\u91cf name \u91cd\u65b0\u8d4b\u503c\uff0c\u800c\u4e0d\u662f\u58f0\u660e\u4e00\u4e2a\u65b0\u53d8\u91cf\u3002<\/p>\n

\u6240\u4ee5\uff0c\u6211\u4eec\u5f97\u51fa\u4e00\u4e2a\u7ed3\u8bba\uff1a\u5728\u540c\u4e00\u4f5c\u7528\u57df\u4f7f\u7528\u77ed\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\u8fdb\u884c\u53d8\u91cf\u58f0\u660e\u65f6\uff0c\u9488\u5bf9\u91cd\u540d\u53d8\u91cf\uff0c\u4e0d\u4f1a\u91cd\u65b0\u751f\u6210\u4e00\u4e2a\u65b0\u53d8\u91cf\uff0c\u800c\u662f\u5bf9\u91cd\u540d\u53d8\u91cf\u8fdb\u884c\u91cd\u65b0\u8d4b\u503c\u3002<\/p>\n

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

\u672c\u6587\u6211\u4eec\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e2a\u4f7f\u7528 Go \u8bed\u8a00\u77ed\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\u8fdb\u884c\u53d8\u91cf\u58f0\u660e\u65f6\uff0c\u6211\u4eec\u975e\u5e38\u5bb9\u6613\u8e29\u7684\u201c\u5751\u201d\u3002<\/p>\n

\u867d\u7136\u95ee\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u8d8a\u662f\u7b80\u5355\u7684\u95ee\u9898\u8d8a\u4e0d\u5bb9\u6613\u6392\u67e5\uff0c\u8fd9\u5c31\u8981\u6c42\u63d0\u5347\u7a0b\u5e8f\u5458\u5bf9 Go \u8bed\u8a00\u76f8\u5173\u77e5\u8bc6\u7684\u638c\u63e1\u6c34\u5e73\uff0c\u5c3d\u91cf\u907f\u514d\u5728\u5f00\u53d1\u65f6\u51fa\u73b0\u6b64\u7c7b\u95ee\u9898\uff0c\u5bfc\u81f4\u53ef\u80fd\u4f1a\u82b1\u8d39\u5927\u91cf\u65f6\u95f4\u6392\u67e5\u95ee\u9898\u3002<\/p>\n

\u6700\u540e\uff0c\u6211\u4eec\u7262\u8bb0 Go \u8bed\u8a00\u7684\u77ed\u53d8\u91cf\u58f0\u660e\u8bed\u6cd5\u7cd6\u5728\u76f8\u540c\u4f5c\u7528\u57df\u548c\u4e0d\u540c\u4f5c\u7528\u57df\u7684\u542b\u4e49\u53ef\u80fd\u4f1a\u4e0d\u540c\uff0c\u8981\u6ce8\u610f\u533a\u5206\u58f0\u660e\u65b0\u53d8\u91cf\u548c\u91cd\u65b0\u8d4b\u503c\u53d8\u91cf\u3002\u200b<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u4f7f\u7528 Go \u8bed\u8a00\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u5728\u5b9a\u4e49\u53d8\u91cf\u65f6\u4f7f\u7528 Go \u8bed\u8a00\u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6 – \u77ed\u53d8\u91cf\u58f0\u660e\uff0c\u5b83\u867d\u7136\u597d […]<\/p>\n","protected":false},"author":1898,"featured_media":249267,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[898],"class_list":["post-249263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-go-"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/249263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=249263"}],"version-history":[{"count":8,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/249263\/revisions"}],"predecessor-version":[{"id":252047,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/249263\/revisions\/252047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/249267"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=249263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=249263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=249263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}