{"id":4055,"date":"2023-10-02T18:33:37","date_gmt":"2023-10-02T09:33:37","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=4055"},"modified":"2025-07-10T19:23:11","modified_gmt":"2025-07-10T10:23:11","slug":"%e3%80%90go%e3%80%91%e4%b8%a6%e5%88%97%e5%87%a6%e7%90%86-%e5%85%a5%e9%96%80","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=4055","title":{"rendered":"\u3010Go\u3011\u4e26\u884c\u51e6\u7406 \u5165\u9580"},"content":{"rendered":"\n<p>DB\u3078\u63a5\u7d9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u308a\u3001Web Api\u3092\u5b9f\u884c\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u308a\u3068\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>DB\u304b\u3089\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\u3001WebApi\u3067\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\u304c\u72ec\u7acb\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u4e00\u65b9\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\u3092\u5f85\u305f\u305a\u306b\u5404\u3005\u304b\u3089\u305d\u308c\u305d\u308c\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u51fa\u6765\u308b\u3068\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u6642\u9593\u304c\u77ed\u7e2e\u3067\u304d\u307e\u3059\u3002Go\u3067\u306f\u305d\u3093\u306a\u6642\u306b\u4e26\u884c\u51e6\u7406\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>Go\u306e\u4e26\u884c\u51e6\u7406\u306e\u57fa\u672c\u3067\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3001\u30c1\u30e3\u30cd\u30eb\u304c\u4e3b\u306a\u767b\u5834\u4eba\u7269\u306b\u306a\u308a\u307e\u3059\u3002\u7279\u306b\u30c1\u30e3\u30cd\u30eb\u306e\u4f7f\u3044\u65b9\u304c\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u30b4\u30eb\u30fc\u30c1\u30f3<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b4\u30eb\u30fc\u30c1\u30f3\u3068\u306f<\/h2>\n\n\n\n<p>Go\u3067\u4e26\u884c\u51e6\u7406\u3092\u5b9f\u73fe\u3059\u308b\u5834\u5408\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f7f\u3044\u307e\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u306fGo\u306e\u30eb\u30fc\u30c1\u30f3\u3067\u3001\u3053\u306e\u30eb\u30fc\u30c1\u30f3\u306fGo\u304c\u53d6\u308a\u6271\u3046\u8efd\u5fae\u306a\u30b9\u30ec\u30c3\u30c9\u306b\u3088\u308a\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u30a4\u30e1\u30fc\u30b8\u3057\u306b\u304f\u3044\u306e\u3067\u5b9f\u969b\u306b\u4f7f\u7528\u3057\u3066\u307f\u305f\u65b9\u304c\u30a4\u30e1\u30fc\u30b8\u3057\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p>\u5b9f\u884c\u3059\u308b\u95a2\u6570\u306e\u524d\u306b go \u3092\u3064\u3051\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002\u3053\u3046\u3059\u308b\u4e8b\u3067\u95a2\u6570\u304c\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3(\u30b4\u30eb\u30fc\u30c1\u30f3)\u3068\u3057\u3066\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u547c\u3073\u51fa\u3057\u5143\u3068\u306f\u5225\u306e\u30b9\u30ec\u30c3\u30c9\u306b\u3088\u308a\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067\u3001\u547c\u3073\u51fa\u3057\u5143\u3068\u547c\u3073\u51fa\u3057\u5148(\u30b4\u30eb\u30fc\u30c1\u30f3)\u306f\u9023\u52d5\u3057\u307e\u305b\u3093\u3002\u975e\u540c\u671f\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>go sampleFunc()<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u4f8b<\/h2>\n\n\n\n<p>\u4f8b\u3068\u3057\u3066\u3001\u51e6\u7406\u306b5\u79d2\u304b\u304b\u308b\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3(\u3044\u3064\u3082\u306emain\u95a2\u6570)\u304b\u3089\u3001\u3053\u306e5\u79d2\u304b\u304b\u308b\u95a2\u6570\u3092\u30b4\u30eb\u30fc\u30c1\u30f3\u3067\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<br>\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3\u3068\u306f\u5225\u306b5\u79d2\u304b\u304b\u308b\u95a2\u6570\u304c\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u3067\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067\u3001\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3\u304c\u5148\u306b\u7d42\u4e86\u3057\u307e\u3059\u3002\u5f93\u3063\u3066\u95a2\u6570sampleGoRoutineA()\u306e&#8221;\u3010\u7d42\u4e86\u3011&#8221;\u306f\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u304c\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3\u3068\u306f\u540c\u671f(\u9023\u52d5?)\u3057\u3066\u3044\u306a\u3044\u4e8b\u304c\u308f\u304b\u308a\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() {\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}\n\nfunc main() {\n\tgo sampleGoRoutineA()\n}\n<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30c1\u30e3\u30cd\u30eb<\/h1>\n\n\n\n<p>\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3\u304c\u5148\u306b\u7d42\u4e86\u3057\u3066\u306f\u610f\u5473\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u306e\u7d50\u679c\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u306d\u3002\u305d\u306e\u5834\u5408\u3001\u30c1\u30e3\u30cd\u30eb\u3068\u3044\u3046\u3082\u306e\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c1\u30e3\u30cd\u30eb\u3068\u306f<\/h2>\n\n\n\n<p>\u30eb\u30fc\u30c1\u30f3(\u95a2\u6570)\u540c\u58eb\u3067\u5024\u306e\u9001\u53d7\u4fe1\u304c\u884c\u3048\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30c1\u30e3\u30cd\u30eb\u5909\u6570<\/h3>\n\n\n\n<p>make\u3092\u4f7f\u3063\u3066\u4f5c\u6210\u3057\u307e\u3059\u3002\u30ad\u30fc\u30ef\u30fc\u30c9chan\u306b\u4f7f\u7528\u3059\u308b\u578b\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>channelA := make(chan string)<\/code><\/pre><\/div>\n\n\n\n<p>make\u3067\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u53c2\u7167\u578b(\u30dd\u30a4\u30f3\u30bf)\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u66f8\u304d\u8fbc\u307f\u3001\u8aad\u307f\u8fbc\u307f<\/h3>\n\n\n\n<p>\u30eb\u30fc\u30c1\u30f3(\u95a2\u6570)\u540c\u58eb\u304c\u30c1\u30e3\u30cd\u30eb\u3092\u901a\u3058\u3066\u5024\u306e\u9001\u53d7\u4fe1\u3092\u884c\u3046\u70ba\u3001\u30c1\u30e3\u30cd\u30eb\u306b\u5bfe\u3057\u3066\u66f8\u304d\u8fbc\u307f\u3001\u8aad\u307f\u8fbc\u307f\u304c\u884c\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306f\u66f8\u304d\u8fbc\u307f\u306e\u4f8b\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>channel &lt;- &quot;sampleGoRoutineA&quot;<\/code><\/pre><\/div>\n\n\n\n<p>\u8aad\u307f\u8fbc\u307f\u306e\u4f8b<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>val := &lt;-channel<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u66f8\u304d\u8fbc\u307f\u3001\u8aad\u307f\u8fbc\u307f\u5c02\u7528<\/h3>\n\n\n\n<p>\u30c1\u30e3\u30cd\u30eb\u3092\u95a2\u6570\u3078\u6e21\u3059\u5834\u5408\u3001\u66f8\u304d\u8fbc\u307f\u5c02\u7528\u304b\u3001\u8aad\u307f\u8fbc\u307f\u5c02\u7528\u304b\u3092\u5ba3\u8a00\u3057\u307e\u3059\u3002<br>\u66f8\u304d\u8fbc\u307f\u3001\u8aad\u307f\u8fbc\u307f\u5c02\u7528\u3068\u3057\u3066\u5ba3\u8a00\u3057\u306a\u304f\u3066\u3082\u52d5\u4f5c\u3057\u307e\u3059\u304c\u3001\u5ba3\u8a00\u3057\u3066\u304a\u304f\u3053\u3068\u3067Go\u304c\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u8aad\u307f\u8fbc\u307f\u5c02\u7528\u306b\u66f8\u304d\u8fbc\u307f\u3092\u884c\u306a\u3063\u3066\u3044\u306a\u3044\u304b\u3001\u307e\u305f\u306f\u305d\u306e\u9006\u3092\u3057\u3066\u3044\u306a\u3044\u304b\u3092\u691c\u77e5\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\/\/ \u66f8\u304d\u8fbc\u307f\u5c02\u7528\nfunc sampleGoRoutineA(channel chan&lt;- string) {\n\t\tchannel &lt;- &quot;sampleGoRoutineA&quot;\n}\n\n\/\/ \u8aad\u307f\u8fbc\u307f\u5c02\u7528\nfunc sampleGoRoutineB(channel &lt;-chan string) {\n\t\tval := &lt;-channel\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u4f8b<\/h2>\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\u4e86 \\n&quot;\n}\n\nfunc main() {\n\tchannelA := make(chan string)\n\tgo sampleGoRoutineA(channelA)\n\tval := &lt;-channelA\n\tfmt.Println(val)\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\u3010\u958b\u59cb\u3011 18:54:23 sampleGoRoutineA \n\u3010\u7d42\u4e86\u3011 18:54:28 sampleGoRoutineA \n\u7d42\u4e86 <\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c1\u30e3\u30cd\u30eb\u306e\u8aac\u660e<\/h2>\n\n\n\n<p>\u4eca\u56de\u306f\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3(main\u95a2\u6570)\u3068\u30b4\u30eb\u30fc\u30c1\u30f3(sampleGoRoutineA\u95a2\u6570)\u304c\u30c1\u30e3\u30cd\u30eb\u3092\u901a\u3058\u3066\u5024\u306e\u9001\u53d7\u4fe1\u3092\u884c\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u30b5\u30d6\u30eb\u30fc\u30c1\u30f3\u306f5\u79d2\u3057\u3066\u304b\u3089\u30c1\u30e3\u30cd\u30eb\u3078\u5024\u306e\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3044\u307e\u3059\u3002\u305d\u306e\u9593\u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3\u3067\u306f\u30b4\u30eb\u30fc\u30c1\u30f3\u3088\u308a\u5148\u306b\u30c1\u30e3\u30cd\u30eb\u3092\u8aad\u307f\u8fbc\u3082\u3046\u3068\u3057\u3066\u51e6\u7406\u3092\u30d6\u30ed\u30c3\u30af(\u5f85\u6a5f)\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>val := &lt;-channelA<\/code><\/pre><\/div>\n\n\n\n<p>5\u79d2\u5f8c\u3001\u30c1\u30e3\u30cd\u30eb\u306b\u5024\u304c\u66f8\u304d\u8fbc\u307e\u308c\u305f\u3089\u30d6\u30ed\u30c3\u30af\u3092\u89e3\u9664\u3057\u3066\u51e6\u7406\u304c\u9032\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u4eca\u56de\u306fGo\u306e\u4e26\u884c\u51e6\u7406\u306b\u5fc5\u8981\u306a\u8981\u7d20\u30b4\u30eb\u30fc\u30c1\u30f3\u3068\u30c1\u30e3\u30cd\u30eb\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3001\u521d\u6b69\u7684\u306a\u4f7f\u3044\u65b9\u3092\u8aac\u660e\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DB\u3078\u63a5\u7d9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u308a\u3001Web Api\u3092\u5b9f\u884c\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u308a\u3068\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u3088\u304f\u3042\u308a\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-4055","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\/4055","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=4055"}],"version-history":[{"count":11,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4055\/revisions"}],"predecessor-version":[{"id":4108,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/4055\/revisions\/4108"}],"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=4055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}