{"id":2444,"date":"2016-09-27T11:54:12","date_gmt":"2016-09-27T11:54:12","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=2444"},"modified":"2016-09-27T11:54:12","modified_gmt":"2016-09-27T11:54:12","slug":"golang-examples-by-examples","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=2444","title":{"rendered":"[Golang] \ud074\ub85c\uc838, \uac00\ubcc0\uc778\uc790 \uc608\uc81c\ucf54\ub4dc"},"content":{"rendered":"<h3>closures<\/h3>\n<p>\uc0c1\ud0dc\uac12\uc744 \uac00\uc9c0\ub294 \ud568\uc218\ub97c \ubc18\ud658\ud558\ub294 \ud568\uc218\uc5d0 \ub300\ud55c \uc608\uc785\ub2c8\ub2e4. <b>(\ucd9c\ucc98: https:\/\/gobyexample.com)<\/b><\/p>\n<pre>\npackage main\n\nimport (\n    \"fmt\"\n)\n\nfunc intSeq() func() int {\n    i := 0\n\n    return func() int {\n        i += 1\n        return i\n    }\n}\n\nfunc main() {\n    nextInt1 := intSeq()\n    nextInt2 := intSeq()\n\n    fmt.Println(nextInt1())\n    fmt.Println(nextInt1())\n    fmt.Println(nextInt1())\n    fmt.Println(nextInt1())\n\n    fmt.Println(nextInt2())\n    fmt.Println(nextInt2())\n    fmt.Println(nextInt2())\n    fmt.Println(nextInt2())\n}\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\n1\n2\n3\n4\n1\n2\n3\n4\n<\/pre>\n<h3>\uac00\ubcc0\uc778\uc790(Variadic)<\/h3>\n<p>\ud568\uc218\uc5d0 \uc784\uc758 \uac1c\uc218\uc758 \uc778\uc790\ub97c \ub118\uae38 \uc218 \uc788\ub294 \uac00\ubcc0\uc778\uc790\ub97c \uac16\ub294 \ud568\uc218\uc5d0 \ub300\ud55c \uc608\uc785\ub2c8\ub2e4. \ud2b9\ud788 \ub124\ubc88\uc9f8 sum \ud568\uc218\uc758 \ud638\ucd9c\uc2dc \uc778\uc790\ub97c \uc2ac\ub77c\uc774\uc2a4\ub85c \uc804\ub2ec \uac00\ub2a5\ud569\ub2c8\ub2e4. <b>(\ucd9c\ucc98: https:\/\/gobyexample.com)<\/b><\/p>\n<pre>\npackage main\n\nimport (\n    \"fmt\"\n)\n\nfunc sum(nums ...int) {\n    fmt.Print(nums, \" \")\n    total := 0\n\n    for _, num := range nums {\n        total += num\n    }\n\n    fmt.Println(total)\n}\n\nfunc main() {\n    sum(1, 2)\n    sum(1, 2, 3)\n    sum(1, 2, 3, 4)\n\n    nums := []int{1, 2, 3, 4}\n    sum(nums...)\n}\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\n[1 2] 3\n[1 2 3] 6\n[1 2 3 4] 10\n[1 2 3 4] 10\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>closures \uc0c1\ud0dc\uac12\uc744 \uac00\uc9c0\ub294 \ud568\uc218\ub97c \ubc18\ud658\ud558\ub294 \ud568\uc218\uc5d0 \ub300\ud55c \uc608\uc785\ub2c8\ub2e4. (\ucd9c\ucc98: https:\/\/gobyexample.com) package main import ( &#8220;fmt&#8221; ) func intSeq() func() int { i := 0 return func() int { i += 1 return i } } func main() { nextInt1 := intSeq() nextInt2 := intSeq() fmt.Println(nextInt1()) fmt.Println(nextInt1()) fmt.Println(nextInt1()) fmt.Println(nextInt1()) fmt.Println(nextInt2()) fmt.Println(nextInt2()) fmt.Println(nextInt2()) fmt.Println(nextInt2()) } \uacb0\uacfc\ub294 \uc544\ub798\uc640 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=2444\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[Golang] \ud074\ub85c\uc838, \uac00\ubcc0\uc778\uc790 \uc608\uc81c\ucf54\ub4dc&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[113],"tags":[],"class_list":["post-2444","post","type-post","status-publish","format-standard","hentry","category-golang"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2444"}],"version-history":[{"count":0,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2444\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2444"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}