{"id":284,"date":"2026-04-23T09:00:00","date_gmt":"2026-04-23T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/"},"modified":"2026-10-10T21:20:54","modified_gmt":"2026-10-10T15:50:54","slug":"go-type-assertion-type-switch","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/","title":{"rendered":"Go Type Assertion and Type Switch Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go type assertion lets you take a value out of an interface and use it as its real, concrete type. In this post, you will use the single value form, the safe &#8220;comma ok&#8221; form and the type switch. Also, each idea comes with a short example that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds directly on <a href=\"https:\/\/smitabharat.com\/blog\/go-interfaces-examples\/\">interfaces in Go with examples<\/a>. You also met <code>map[string]any<\/code> in <a href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\">Go JSON encoding and decoding<\/a>. In fact, type assertions are how you read those values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Type Assertion?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An interface value is like a gift box with a label. The label says &#8220;any&#8221; or &#8220;Stringer&#8221;, but the real item sits inside. Then a type assertion opens the box and says &#8220;I expect a string in here&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var v any = \"hello\"\ns := v.(string)\nfmt.Println(s, len(s)) \/\/ hello 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In short, the syntax is <code>value.(Type)<\/code>. If the guess is right, you get the concrete value. Then you can call <code>len<\/code> and other string operations on it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When a Go Type Assertion Fails<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>var w any = 42\n_ = w.(string)\n\/\/ panic: interface conversion: interface {} is int, not string<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A wrong guess with the single value form causes a panic. In other words, a Go type assertion without <code>ok<\/code> trusts you completely. Therefore, use this form only when you are completely sure about the type.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Safe comma ok Form<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>n, ok := v.(int)\nfmt.Println(n, ok) \/\/ 0 false\n\nif str, ok := v.(string); ok {\n\tfmt.Println(\"it is a string:\", str)\n}\n\/\/ it is a string: hello<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, with two results, a wrong guess never panics. Instead, <code>ok<\/code> becomes <code>false<\/code>, and the value is the zero value of the type. Indeed, this is the same &#8220;comma ok&#8221; idea you used with <a href=\"https:\/\/smitabharat.com\/blog\/go-maps-examples\/\">maps in Go<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Type Switches: Checking Many Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a value could be one of several types, a type switch is cleaner than a chain of assertions. For example, the diagram below shows one value flowing into the matching case.<\/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-type-assertion-type-switch-diagram-1024x640.png\" alt=\"Go Type Assertion diagram showing a type switch matching the int case for the value 21\" class=\"wp-image-259\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>A type switch checks the dynamic type inside the interface and runs the first case that matches.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func describe(v any) string {\n\tswitch x := v.(type) {\n\tcase int:\n\t\treturn \"int doubled: \" + strconv.Itoa(x*2)\n\tcase string:\n\t\treturn \"string of length \" + strconv.Itoa(len(x))\n\tcase bool:\n\t\treturn fmt.Sprint(\"bool flipped: \", !x)\n\tcase nil:\n\t\treturn \"nil value\"\n\tdefault:\n\t\treturn fmt.Sprintf(\"other type %T\", x)\n\t}\n}\n\nfmt.Println(describe(21))   \/\/ int doubled: 42\nfmt.Println(describe(\"Go\")) \/\/ string of length 2\nfmt.Println(describe(true)) \/\/ bool flipped: false\nfmt.Println(describe(nil))  \/\/ nil value\nfmt.Println(describe(3.14)) \/\/ other type float64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inside each case, <code>x<\/code> already has the matching type, so no extra Go type assertion is needed. So in the <code>int<\/code> case you can multiply it, and in the <code>string<\/code> case you can take its length.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Type Assertion to an Interface<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>type Celsius float64\n\nfunc (c Celsius) String() string {\n\treturn strconv.FormatFloat(float64(c), 'f', 1, 64) + \"\u00b0C\"\n}\n\nvar t any = Celsius(20)\nif st, ok := t.(fmt.Stringer); ok {\n\tfmt.Println(st.String()) \/\/ 20.0\u00b0C\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also assert to another interface. In that case, the check asks whether the value has those methods. For example, this pattern lets a function add extra features when a value supports them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Type Assertion vs Type Conversion<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Type assertion<\/th><th>Type conversion<\/th><\/tr><\/thead><tbody><tr><td>Syntax<\/td><td><code>v.(string)<\/code><\/td><td><code>float64(n)<\/code><\/td><\/tr><tr><td>Works on<\/td><td>Interface values only<\/td><td>Concrete values<\/td><\/tr><tr><td>Checked at<\/td><td>Run time<\/td><td>Compile time<\/td><\/tr><tr><td>Can panic<\/td><td>Yes, single value form<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, a conversion changes a value from one type to another. Also, it works on any compatible types and never fails at run time. An assertion, however, only reveals the type that is already inside an interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Type Assertion<\/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>panic: interface conversion: interface {} is int, not string<\/td><td>Because the guess was wrong.<\/td><td>So use the comma ok form.<\/td><\/tr><tr><td>invalid operation: x (variable of type int) is not an interface<\/td><td>Because the value is not an interface.<\/td><td>So use a conversion instead.<\/td><\/tr><tr><td>JSON number fails as int<\/td><td>Because decoded numbers are float64.<\/td><td>So assert to float64 first.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also, when you check errors, prefer <code>errors.As<\/code> over a raw assertion, because it looks through wrapped errors too. Interface questions are common in interviews, so practise with 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#Type_assertions\">Go spec: Type assertions<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Type_switches\">Go spec: Type switches<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/tour\/methods\/15\">A Tour of Go: Type assertions<\/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>Go type assertion reads the concrete value inside an interface.<\/li>\n\n\n\n<li>The single value form panics on a wrong guess.<\/li>\n\n\n\n<li>The comma ok form returns false instead of panicking.<\/li>\n\n\n\n<li>A type switch handles many possible types cleanly.<\/li>\n\n\n\n<li>You can also assert to another interface, such as fmt.Stringer.<\/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\">Finally, you can look inside any interface. Next, we will reuse code by placing one struct inside another with struct embedding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-struct-embedding-examples\/\">Go Struct Embedding Explained with Examples<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go type assertion lets you take a value out of an interface and use it as its real, concrete type. In this post, you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":258,"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":[11,23,50,21],"swapz_series":[],"class_list":["post-284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-tutorial","tag-go-type-assertion","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 Type Assertion and Type Switch Explained<\/title>\n<meta name=\"description\" content=\"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.\" \/>\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-type-assertion-type-switch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Type Assertion and Type Switch Explained\" \/>\n<meta property=\"og:description\" content=\"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-23T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-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-type-assertion-type-switch\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Type Assertion and Type Switch Explained\",\"datePublished\":\"2026-04-23T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/\"},\"wordCount\":651,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-type-assertion-type-switch-featured.png\",\"keywords\":[\"Go Lang\",\"Go Tutorial\",\"Go Type Assertion\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/\",\"name\":\"Go Type Assertion and Type Switch Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-type-assertion-type-switch-featured.png\",\"datePublished\":\"2026-04-23T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:54+00:00\",\"description\":\"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-type-assertion-type-switch-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-type-assertion-type-switch-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Type Assertion featured image: cards for v.(T), the comma ok form and type switches\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-type-assertion-type-switch\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Type Assertion and Type Switch 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 Type Assertion and Type Switch Explained","description":"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.","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-type-assertion-type-switch\/","og_locale":"en_US","og_type":"article","og_title":"Go Type Assertion and Type Switch Explained","og_description":"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.","og_url":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-23T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:54+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-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-type-assertion-type-switch\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Type Assertion and Type Switch Explained","datePublished":"2026-04-23T03:30:00+00:00","dateModified":"2026-10-10T15:50:54+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/"},"wordCount":651,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-featured.png","keywords":["Go Lang","Go Tutorial","Go Type Assertion","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/","url":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/","name":"Go Type Assertion and Type Switch Explained","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-featured.png","datePublished":"2026-04-23T03:30:00+00:00","dateModified":"2026-10-10T15:50:54+00:00","description":"Learn Go type assertion with simple examples: read the real type in an interface, use the comma ok form and write type switches.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-type-assertion-type-switch-featured.png","width":2400,"height":1260,"caption":"Go Type Assertion featured image: cards for v.(T), the comma ok form and type switches"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Type Assertion and Type Switch 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\/284","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=284"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions\/311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/258"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=284"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}