{"id":2464,"date":"2018-10-05T02:48:44","date_gmt":"2018-10-04T17:48:44","guid":{"rendered":"http:\/\/okamurax.com\/?p=2464"},"modified":"2020-05-06T00:17:49","modified_gmt":"2020-05-05T15:17:49","slug":"golang-%e3%83%81%e3%83%a3%e3%83%b3%e3%83%8d%e3%83%ab","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=2464","title":{"rendered":"golang \u30c1\u30e3\u30f3\u30cd\u30eb"},"content":{"rendered":"<pre class=\"lang:go decode:true \">package main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"log\"\r\n)\r\n\r\nfunc main() {\r\n\r\n\t\/\/\u5b9a\u7fa9\r\n\tc := make(chan int)\r\n\r\n\t\/*\r\n\t\tcapacity\u306fchannel\u5185\u3067\u306e\u30d0\u30c3\u30d5\u30a1\r\n\t\tcapacity\u306b\u7a7a\u304d\u304c\u306a\u3044\u3068\u9001\u4fe1\u5074\u3067\u51e6\u7406\u5f85\u3061\u306b\u306a\u308b\r\n\r\n\t\t\u975e\u540c\u671f\u306e\u7d42\u4e86\u5f85\u3061\u306f\u9014\u4e2d\u3067\u629c\u3051\u308b\u3068\u9001\u4fe1\u5074\u306e\u51e6\u7406\u5f85\u3061\u304c\u6b8b\u3063\u3066\u3057\u307e\u3046\r\n\r\n\t\tclose\u3057\u305f\u30c1\u30e3\u30f3\u30cd\u30eb\u306f\u64cd\u4f5c\u3067\u304d\u306a\u3044\r\n\t*\/\r\n\r\n\tgo func(s chan&lt;- int) {\r\n\r\n\t\tfor i := 0; i &lt; 5; i++ {\r\n\t\t\ts &lt;- i \/\/\u9001\u4fe1\r\n\t\t}\r\n\r\n\t\tclose(s) \/\/\u53d7\u4fe1\u5074\u3067close\u3092\u691c\u77e5\u3059\u308b\r\n\r\n\t}(c) \/\/\u5373\u6642\u95a2\u6570\u306e\u5f15\u6570\u306bc\u3092\u6e21\u3057\u3066\u3044\u308b\r\n\r\n\t\/\/close\u5f85\u3061\u3059\u308b\u5834\u5408(\u975e\u540c\u671f\u306e\u7d42\u4e86\u5f85\u3061)\r\n\t&lt;-c\r\n\r\n\t\/\/for-range\u3067\u53d7\u4fe1\r\n\tfor v := range c {\r\n\t\tfmt.Println(v)\r\n\t}\r\n\r\n\t\/\/for\u3067\u53d7\u4fe1\r\n\t\/\/close\u306e\u5834\u5408ok\u304cfalse\r\n\tfor {\r\n\t\tvalue, ok := &lt;-c\r\n\t\tif !ok {\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tfmt.Println(value)\r\n\t}\r\n\r\n\t\/\/\u3059\u3079\u3066\u53d7\u4fe1(close\u306e\u5834\u54080)\r\n\tvv := &lt;-c\r\n\tlog.Print(\"_\", vv)\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>package main import ( &#8220;fmt&#8221; &#8220;log&#8221; ) func main() { \/\/\u5b9a\u7fa9 c := make(chan int) \/* capacity\u306fchannel\u5185\u3067\u306e\u30d0\u30c3\u30d5\u30a1 capacity &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=2464\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;golang \u30c1\u30e3\u30f3\u30cd\u30eb&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[148],"class_list":["post-2464","post","type-post","status-publish","format-standard","hentry","category-1","tag-golang"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2464"}],"version-history":[{"count":1,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2464\/revisions"}],"predecessor-version":[{"id":2465,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2464\/revisions\/2465"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}