{"id":3698,"date":"2022-12-30T13:38:49","date_gmt":"2022-12-30T05:38:49","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3698"},"modified":"2022-12-30T13:38:49","modified_gmt":"2022-12-30T05:38:49","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e5%b9%b6%e7%99%bc%e6%8a%80%e8%a1%93","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%e5%b9%b6%e7%99%bc%e6%8a%80%e8%a1%93\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u4e2d\u7684\u5e76\u767c\u6280\u8853"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, \u5e76\u767c\"><\/p>\n<h1>\u4f7f\u7528 Go \u8a9e\u8a00\u5be6\u73fe\u5e76\u767c<\/h1>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u9069\u5408\u7528\u4f86\u5be6\u73fe\u5e76\u767c\u7684\u8a9e\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u5f0f\u4f86\u5be6\u73fe\u5e76\u767c\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86 goroutine \u548c channel \u4f86\u5be6\u73fe\u5e76\u767c\uff0cgoroutine \u662f\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7684\u7dda\u7a0b\uff0c\u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c channel \u5247\u662f\u4e00\u7a2e\u7528\u65bc\u5728 goroutine \u4e4b\u9593\u9032\u884c\u6e9d\u901a\u7684\u6a5f\u5236\u3002<\/p>\n<h2>goroutine<\/h2>\n<p>goroutine \u662f Go \u8a9e\u8a00\u4e2d\u7528\u65bc\u5be6\u73fe\u5e76\u767c\u7684\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7dda\u7a0b\uff0c\u5b83\u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\u3002goroutine \u662f Go \u8a9e\u8a00\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u4f60\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002<\/p>\n<p>goroutine \u662f\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7684\u7dda\u7a0b\uff0c\u5b83\u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002goroutine \u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002goroutine \u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002<\/p>\n<p><!--more--><\/p>\n<p>goroutine \u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002goroutine \u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002goroutine \u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\u3002<\/p>\n<h2>Channel<\/h2>\n<p>Channel \u662f Go \u8a9e\u8a00\u4e2d\u7528\u65bc\u5728 goroutine \u4e4b\u9593\u9032\u884c\u6e9d\u901a\u7684\u6a5f\u5236\uff0c\u5b83\u53ef\u4ee5\u8b93 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\u3002Channel \u53ef\u4ee5\u8b93 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\uff0c\u5b83\u53ef\u4ee5\u8b93 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\u3002Channel \u53ef\u4ee5\u8b93 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\uff0c\u5b83\u53ef\u4ee5\u8b93 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\u3002<\/p>\n<pre class=\"brush: go\">\n\/\/ \u5275\u5efa\u4e00\u500b channel\nch := make(chan int)\n\n\/\/ \u5411 channel \u767c\u9001\u6578\u64da\ngo func() {\n    ch <- 1\n}()\n\n\/\/ \u5f9e channel \u63a5\u6536\u6578\u64da\ngo func() {\n    data := <-ch\n    fmt.Println(data)\n}()\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 channel \u4f86\u5728 goroutine \u4e4b\u9593\u9032\u884c\u6578\u64da\u7684\u4ea4\u63db\u548c\u540c\u6b65\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u9069\u5408\u7528\u4f86\u5be6\u73fe\u5e76\u767c\u7684\u8a9e\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u5f0f\u4f86\u5be6\u73fe\u5e76\u767c\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86 goroutine \u548c channel \u4f86\u5be6\u73fe\u5e76\u767c\uff0cgoroutine \u662f\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7684\u7dda\u7a0b\uff0c\u53ef\u4ee5\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c channel \u5247\u662f\u4e00\u7a2e\u7528\u65bc\u5728 goroutine \u4e4b\u9593\u9032\u884c\u6e9d\u901a\u7684\u6a5f\u5236\u3002\u4f7f\u7528 goroutine \u548c channel \u53ef\u4ee5\u8b93\u4f60\u5728\u4e00\u500b\u55ae\u7368\u7684\u9032\u7a0b\u4e2d\u57f7\u884c\u591a\u500b\u4efb\u52d9\uff0c\u800c\u4e0d\u9700\u8981\u591a\u500b\u9032\u7a0b\uff0c\u9019\u6a23\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5229\u7528\u7cfb\u7d71\u8cc7\u6e90\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u8a9e\u8a00\u662f\u4e00\u7a2e\u9ad8\u6548\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u652f\u6301\u5e76\u767c\u6280\u8853\uff0c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5229\u7528\u8a08\u7b97\u6a5f\u8cc7\u6e90\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u3002\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684\u5e76\u767c\u6280\u8853\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\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-3698","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-XE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3698","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=3698"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3698\/revisions"}],"predecessor-version":[{"id":3699,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3698\/revisions\/3699"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}