{"id":282,"date":"2026-04-21T09:00:00","date_gmt":"2026-04-21T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/"},"modified":"2026-10-10T21:20:52","modified_gmt":"2026-10-10T15:50:52","slug":"go-closures-anonymous-functions","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/","title":{"rendered":"Go Closures and Anonymous Functions Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go closures are functions that remember the variables around them, even after the outer function has finished. In this post, you will write anonymous functions and build a counter that keeps its own state. Then you will create functions that make other functions. Each idea comes with a short example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Closures build on the basics from <a href=\"https:\/\/smitabharat.com\/blog\/go-functions-beginners-guide\/\">writing and calling functions in Go<\/a>. They also appear inside goroutines all the time, which you met in <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutines-beginners-guide\/\">goroutines in Go for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Anonymous Functions First<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An anonymous function is simply a function without a name. You can store it in a variable, pass it to another function or run it right away.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>greet := func(name string) string {\n\treturn \"Hello, \" + name\n}\nfmt.Println(greet(\"Asha\")) \/\/ Hello, Asha\n\nfunc(msg string) {\n\tfmt.Println(msg)\n}(\"runs right away\") \/\/ runs right away<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The second example ends with <code>(\"runs right away\")<\/code>, so Go calls it immediately. Developers often use this style with <code>defer<\/code> and <code>go<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Closures?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A closure is an anonymous function that uses a variable from outside its own body. The function &#8220;closes over&#8221; that variable and keeps it alive. For example, think of a backpack. Wherever the function goes, it carries its variables along.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func counter() func() int {\n\tcount := 0\n\treturn func() int {\n\t\tcount++\n\t\treturn count\n\t}\n}\n\nnext := counter()\nfmt.Println(next(), next(), next()) \/\/ 1 2 3\n\nother := counter()\nfmt.Println(other()) \/\/ 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Normally, <code>count<\/code> would vanish when <code>counter<\/code> returns. However, the inner function still uses it, so Go keeps it alive. The diagram below shows why <code>next<\/code> and <code>other<\/code> keep separate counts.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-1024x640.png\" alt=\"Go Closures diagram showing two counters that each remember their own count variable\" class=\"wp-image-255\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Each call to counter() creates a fresh count variable, and each returned closure carries its own copy along.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Closures as Function Factories<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func multiplier(n int) func(int) int {\n\treturn func(x int) int { return x * n }\n}\n\ndouble := multiplier(2)\ntriple := multiplier(3)\nfmt.Println(double(5), triple(5)) \/\/ 10 15<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In short, <code>multiplier<\/code> is a factory. It builds new functions, and each one remembers its own <code>n<\/code>. This pattern also creates HTTP middleware and custom validators.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Closures as Callbacks<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>people := []string{\"Ravi\", \"Asha\", \"Meera\"}\nsort.Slice(people, func(i, j int) bool {\n\treturn people[i] &lt; people[j]\n})\nfmt.Println(people) \/\/ [Asha Meera Ravi]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here the closure reads <code>people<\/code> from the outer scope. So <code>sort.Slice<\/code> only needs a tiny &#8220;less than&#8221; rule from you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Changing Outer Variables<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>total := 0\nadd := func(n int) { total += n }\nadd(10)\nadd(5)\nfmt.Println(total) \/\/ 15<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A closure shares the variable itself, not a copy of its value. As a result, changes inside the closure are visible outside too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Closures in Loops<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>var funcs []func()\nfor i := 0; i &lt; 3; i++ {\n\tfuncs = append(funcs, func() { fmt.Print(i, \" \") })\n}\nfor _, f := range funcs {\n\tf()\n}\n\/\/ Go 1.22 and later: 0 1 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Before Go 1.22, every closure in this loop shared one <code>i<\/code>, so the program printed &#8220;3 3 3&#8221;. Since Go 1.22, however, each loop iteration gets a fresh variable. Therefore, Go closures created in a loop now behave the way most people expect. Make sure your <code>go.mod<\/code> says <code>go 1.22<\/code> or later to get this behaviour.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Use Go Closures<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use Go closures when a small piece of behaviour needs a little private state. For example, a rate limiter can remember when it last ran. Likewise, an ID generator can remember the last number it used. Closures also keep helper code next to the place that uses it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, a closure is not always the best tool. If the state grows large or needs many methods, a struct with methods is clearer. In short, choose a closure for one small job and a struct for anything bigger.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Closures<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>Loop prints the last value every time<\/td><td>The module uses Go 1.21 or older.<\/td><td>Raise the go line in go.mod to 1.22 or later.<\/td><\/tr><tr><td>Data race warning with goroutines<\/td><td>Many closures change one variable together.<\/td><td>Protect it with a mutex or use channels.<\/td><\/tr><tr><td>Memory stays in use<\/td><td>A long-lived closure keeps a large variable alive.<\/td><td>Capture only the small value you need.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The data race case is common, so revisit <a href=\"https:\/\/smitabharat.com\/blog\/go-sync-package-waitgroup-mutex\/\">the Go sync package<\/a> if it sounds new. Closure questions are also an interview favourite, so try my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they stay accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Function_literals\">Go spec: Function literals<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/loopvar-preview\">Go blog: Fixing For Loops in Go 1.22<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/tour\/moretypes\/25\">A Tour of Go: Function closures<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An anonymous function has no name and can run immediately.<\/li>\n\n\n\n<li>Go closures remember the variables they use from outside.<\/li>\n\n\n\n<li>Each call to a factory function creates fresh captured variables.<\/li>\n\n\n\n<li>Closures share variables, so changes are visible outside.<\/li>\n\n\n\n<li>Since Go 1.22, each loop iteration gets its own variable.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Functions can now remember state. Next, we will see what happens when a program crashes and how defer, panic and recover handle it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-defer-panic-recover\/\">Go Panic and Recover with Defer Explained<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go closures are functions that remember the variables around them, even after the outer function has finished. In this post, you will write anonymous&hellip;<\/p>\n","protected":false},"author":1,"featured_media":254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[48,11,23,21],"swapz_series":[],"class_list":["post-282","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-closures","tag-go-lang","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Closures and Anonymous Functions Explained<\/title>\n<meta name=\"description\" content=\"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Closures and Anonymous Functions Explained\" \/>\n<meta property=\"og:description\" content=\"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-21T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Closures and Anonymous Functions Explained\",\"datePublished\":\"2026-04-21T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/\"},\"wordCount\":664,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-closures-anonymous-functions-featured.png\",\"keywords\":[\"Go Closures\",\"Go Lang\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/\",\"name\":\"Go Closures and Anonymous Functions Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-closures-anonymous-functions-featured.png\",\"datePublished\":\"2026-04-21T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:52+00:00\",\"description\":\"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-closures-anonymous-functions-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-closures-anonymous-functions-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Closures featured image: cards for anonymous functions, state and factories\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-closures-anonymous-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Closures and Anonymous Functions Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Closures and Anonymous Functions Explained","description":"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/","og_locale":"en_US","og_type":"article","og_title":"Go Closures and Anonymous Functions Explained","og_description":"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.","og_url":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-21T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:52+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Closures and Anonymous Functions Explained","datePublished":"2026-04-21T03:30:00+00:00","dateModified":"2026-10-10T15:50:52+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/"},"wordCount":664,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png","keywords":["Go Closures","Go Lang","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/","url":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/","name":"Go Closures and Anonymous Functions Explained","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png","datePublished":"2026-04-21T03:30:00+00:00","dateModified":"2026-10-10T15:50:52+00:00","description":"Learn Go closures with simple examples: anonymous functions, counters that remember state, function factories and the Go 1.22 loop fix.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-closures-anonymous-functions-featured.png","width":2400,"height":1260,"caption":"Go Closures featured image: cards for anonymous functions, state and factories"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Closures and Anonymous Functions Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=282"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/282\/revisions\/297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=282"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}