{"id":4083,"date":"2023-10-03T19:48:25","date_gmt":"2023-10-03T10:48:25","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=4083"},"modified":"2025-07-10T19:22:58","modified_gmt":"2025-07-10T10:22:58","slug":"%e3%80%90go%e3%80%91%e3%83%81%e3%83%a3%e3%83%8d%e3%83%ab%e3%81%ae%e8%a4%87%e6%95%b0%e6%89%b1%e3%81%84","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=4083","title":{"rendered":"\u3010Go\u3011\u30c1\u30e3\u30cd\u30eb\u306e\u8907\u6570\u6271\u3044"},"content":{"rendered":"\n<p>\u30c1\u30e3\u30cd\u30eb\u3092\u8907\u6570\u6271\u3063\u305f\u6642\u306e\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 class=\"wp-block-heading\">\u5358\u7d14\u306b\u8907\u6570\u4f7f\u3063\u3066\u307f\u308b<\/h1>\n\n\n\n<p>\u5358\u7d14\u306b\u30c1\u30e3\u30cd\u30eb\u3092\u8907\u6570\u4f7f\u7528\u3057\u305f\u30b1\u30fc\u30b9\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002<br>\u51e6\u7406\u306b10\u79d2\u304b\u304b\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u3068\u51e6\u7406\u306b5\u79d2\u304b\u304b\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u7528\u610f\u3057\u3001\u305d\u308c\u305e\u308c\u306b\u5225\u3005\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u5148\u306b\u66f8\u304f<\/h2>\n\n\n\n<p>\u63b2\u984c\u306e\u901a\u308a\u3067\u3059\u304c\u3001\u51e6\u7406\u306b10\u79d2\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30ebB\u306e\u8aad\u307f\u8fbc\u307f\u3068\u305d\u306e\u8868\u793a\u3092\u3001\u51e6\u7406\u306b5\u79d2\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30ebA\u3088\u308a\u3082\u5148\u306b\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc sampleGoRoutineA(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\ttime.Sleep(5 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86A&quot;\n\tclose(channel)\n}\n\nfunc sampleGoRoutineB(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\ttime.Sleep(10 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86B&quot;\n\tclose(channel)\n}\n\nfunc main() {\n\tchannelA := make(chan string)\n\tchannelB := make(chan string)\n\tgo sampleGoRoutineA(channelA)\n\tgo sampleGoRoutineB(channelB)\n\n\t\/\/ \u3042\u3048\u3066A\u3088\u308a\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u308bB\u306e\u8aad\u307f\u8fbc\u307f\u3092\u5148\u306b\u66f8\u3044\u3066\u307f\u308b\n\tb := &lt;-channelB\n\tfmt.Printf(b + &quot;: &quot; + time.Now().Format(time.TimeOnly) + &quot;\\n&quot;)\n\n\ta := &lt;-channelA\n\tfmt.Printf(a + &quot;: &quot; + time.Now().Format(time.TimeOnly) + &quot;\\n&quot;)\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>\u51e6\u7406\u306b5\u79d2\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30ebA\u304c\u7d42\u4e86\u3059\u308b\u3068\u3001B\u306e\u8aad\u307f\u8fbc\u307f\u5b8c\u4e86\u3092\u7121\u8996\u3057\u3066\u51e6\u7406\u304c\u9032\u3080\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u30c1\u30e3\u30cd\u30ebB\u304c\u51e6\u7406\u3092\u30d6\u30ed\u30c3\u30af\u3057\u3066\u3044\u3066\u3001\u30a8\u30e9\u30fc\u306a\u304f\u6b63\u5e38\u306b\u52d5\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\u3010\u958b\u59cb\u3011 20:00:34 sampleGoRoutineB \n\u3010\u958b\u59cb\u3011 20:00:34 sampleGoRoutineA \n\u3010\u7d42\u4e86\u3011 20:00:39 sampleGoRoutineA \n\u3010\u7d42\u4e86\u3011 20:00:44 sampleGoRoutineB \n\u7d42\u4e86B: 20:00:44\n\u7d42\u4e86A: 20:00:44  <\/code><\/pre><\/div>\n\n\n\n<p>\u51e6\u7406\u304c\u65e9\u304f\u7d42\u308f\u308b\u30c1\u30e3\u30cd\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u5148\u306b\u66f8\u304f<\/p>\n\n\n\n<p>\u5148\u307b\u3069\u3068\u306f\u9006\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc sampleGoRoutineA(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\ttime.Sleep(5 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86A&quot;\n\tclose(channel)\n}\n\nfunc sampleGoRoutineB(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\ttime.Sleep(10 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86B&quot;\n\tclose(channel)\n}\n\nfunc main() {\n\tchannelA := make(chan string)\n\tchannelB := make(chan string)\n\tgo sampleGoRoutineA(channelA)\n\tgo sampleGoRoutineB(channelB)\n\n\t\/\/ \u3042\u3048\u3066\u51e6\u7406\u306e\u65e9\u3044A\u306e\u8aad\u307f\u8fbc\u307f\u3092\u5148\u306b\u66f8\u3044\u3066\u307f\u308b\n\ta := &lt;-channelA\n\tfmt.Printf(a + &quot;: &quot; + time.Now().Format(time.TimeOnly) + &quot;\\n&quot;)\n\n\tb := &lt;-channelB\n\tfmt.Printf(b + &quot;: &quot; + time.Now().Format(time.TimeOnly) + &quot;\\n&quot;)\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u5148\u307b\u3069\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001\u51e6\u7406\u306b5\u79d2\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30ebA\u304c\u7d42\u4e86\u3059\u308b\u3068\u3001\u30c1\u30e3\u30cd\u30ebA\u306e\u8868\u793a\u306f\u884c\u308f\u308c\u307e\u3057\u305f\u304c\u3001\u30c1\u30e3\u30cd\u30ebB\u304c\u51e6\u7406\u3092\u30d6\u30ed\u30c3\u30af\u3057\u3066\u3044\u3066\u3001\u30a8\u30e9\u30fc\u306a\u304f\u6b63\u5e38\u306b\u52d5\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\u3010\u958b\u59cb\u3011 20:02:54 sampleGoRoutineA \n\u3010\u958b\u59cb\u3011 20:02:54 sampleGoRoutineB \n\u3010\u7d42\u4e86\u3011 20:02:59 sampleGoRoutineA \n\u7d42\u4e86A: 20:02:59\n\u3010\u7d42\u4e86\u3011 20:03:04 sampleGoRoutineB \n\u7d42\u4e86B: 20:03:04<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30af\u30ed\u30fc\u30ba\u5224\u5b9a\u3059\u308b<\/h1>\n\n\n\n<p>for range\u3092\u4f7f\u7528\u3057\u3066\u30af\u30ed\u30fc\u30ba\u3055\u308c\u305f\u4e8b\u3092\u691c\u77e5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;time&quot;\n)\n\nfunc sampleGoRoutineA(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\ttime.Sleep(5 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineA \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86A \\n&quot;\n\tclose(channel)\n}\n\nfunc sampleGoRoutineB(channel chan&lt;- string) {\n\tfmt.Printf(&quot;\u3010\u958b\u59cb\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\ttime.Sleep(5 * time.Second)\n\tfmt.Printf(&quot;\u3010\u7d42\u4e86\u3011 &quot; + time.Now().Format(time.TimeOnly) + &quot; sampleGoRoutineB \\n&quot;)\n\tchannel &lt;- &quot;\u7d42\u4e86B \\n&quot;\n\tclose(channel)\n}\n\nfunc main() {\n\tchannelA := make(chan string)\n\tchannelB := make(chan string)\n\tgo sampleGoRoutineA(channelA)\n\tgo sampleGoRoutineB(channelB)\n\n\t\/\/ \u3042\u3048\u3066A\u3088\u308a\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u308bB\u306e\u8aad\u307f\u8fbc\u307f\u3092\u5148\u306b\u66f8\u3044\u3066\u307f\u308b\n\tfor valB := range channelB {\n\t\tfmt.Printf(valB)\n\t}\n\n\tfor valA := range channelA {\n\t\tfmt.Printf(valA)\n\t}\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u6b63\u5e38\u306b\u52d5\u304d\u307e\u3057\u305f\u3002\u305f\u3060\u3057\u5148\u307b\u3069\u3068\u9055\u3044\u3001&#8221;\u7d42\u4e86B&#8221; \u304c\u8868\u793a\u3055\u308c\u3066\u304b\u3089\u3001&#8221;\u7d42\u4e86A&#8221;\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br>\u3053\u308c\u306f\u3001\u51e6\u7406\u306b10\u79d2\u304b\u304b\u308b\u30c1\u30e3\u30cd\u30ebB\u306efor range\u304c\u51e6\u7406\u3092\u30d6\u30ed\u30c3\u30af\u3057\u3066\u3044\u308b\u304b\u3089\u3068\u63a8\u6e2c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\u3010\u958b\u59cb\u3011 19:51:02 sampleGoRoutineB \n\u3010\u958b\u59cb\u3011 19:51:02 sampleGoRoutineA \n\u3010\u7d42\u4e86\u3011 19:51:07 sampleGoRoutineA \n\u3010\u7d42\u4e86\u3011 19:51:07 sampleGoRoutineB \n\u7d42\u4e86B \n\u7d42\u4e86A <\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30c1\u30e3\u30cd\u30eb\u3092\u8907\u6570\u6271\u3063\u305f\u6642\u306e\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":968,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-4083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4083"}],"version-history":[{"count":6,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4083\/revisions"}],"predecessor-version":[{"id":4089,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4083\/revisions\/4089"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/968"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}