{"id":4909,"date":"2024-03-14T02:05:51","date_gmt":"2024-03-14T02:05:51","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/"},"modified":"2025-07-31T15:09:47","modified_gmt":"2025-07-31T15:09:47","slug":"what-is-the-usage-of-the-go-keyword","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/","title":{"rendered":"Go Enum Implementation Using Constants and Iota"},"content":{"rendered":"<p>In Go language, enumeration can be achieved by defining constant groups using the const keyword. Even though Go language does not have an enum type, the same effect can be accomplished by using constant groups.<\/p>\n<p>Here is an example code using a constant group to implement an enumeration:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">package<\/span> main\r\n\r\n<span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-string\">\"fmt\"<\/span>\r\n\r\n<span class=\"hljs-keyword\">const<\/span> (\r\n    Sunday    = <span class=\"hljs-literal\">iota<\/span> <span class=\"hljs-comment\">\/\/ 0<\/span>\r\n    Monday           <span class=\"hljs-comment\">\/\/ 1<\/span>\r\n    Tuesday          <span class=\"hljs-comment\">\/\/ 2<\/span>\r\n    Wednesday        <span class=\"hljs-comment\">\/\/ 3<\/span>\r\n    Thursday         <span class=\"hljs-comment\">\/\/ 4<\/span>\r\n    Friday           <span class=\"hljs-comment\">\/\/ 5<\/span>\r\n    Saturday         <span class=\"hljs-comment\">\/\/ 6<\/span>\r\n)\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">func<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span><\/span> {\r\n    day := Monday\r\n\r\n    <span class=\"hljs-keyword\">switch<\/span> day {\r\n    <span class=\"hljs-keyword\">case<\/span> Sunday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Sunday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Monday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Monday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Tuesday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Tuesday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Wednesday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Wednesday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Thursday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Thursday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Friday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Friday\"<\/span>)\r\n    <span class=\"hljs-keyword\">case<\/span> Saturday:\r\n        fmt.Println(<span class=\"hljs-string\">\"Saturday\"<\/span>)\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>In the code above, we defined a group of constants using the const keyword, and each constant is assigned an incremented value using iota to mimic an enumeration. We then used a switch statement in the main function to output the corresponding day of the week based on the enum value.<\/p>\n<p>Overall, Go language does not have a native enumeration type, but the effect of enumeration can be achieved through constant groups.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Go language, enumeration can be achieved by defining constant groups using the const keyword. Even though Go language does not have an enum type, the same effect can be accomplished by using constant groups. Here is an example code using a constant group to implement an enumeration: package main import &#8220;fmt&#8221; const ( Sunday [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[4927,2690,4928,4095,4923],"class_list":["post-4909","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-constants","tag-enum","tag-go-language","tag-go-programming","tag-iota"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Go Enum Implementation Using Constants and Iota - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn&#039;t have a native enum type.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Enum Implementation Using Constants and Iota\" \/>\n<meta property=\"og:description\" content=\"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn&#039;t have a native enum type.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-14T02:05:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T15:09:47+00:00\" \/>\n<meta name=\"author\" content=\"Emily Johnson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emily Johnson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\"},\"author\":{\"name\":\"Emily Johnson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\"},\"headline\":\"Go Enum Implementation Using Constants and Iota\",\"datePublished\":\"2024-03-14T02:05:51+00:00\",\"dateModified\":\"2025-07-31T15:09:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\"},\"wordCount\":127,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"constants\",\"enum\",\"Go language\",\"Go programming\",\"iota\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\",\"name\":\"Go Enum Implementation Using Constants and Iota - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-14T02:05:51+00:00\",\"dateModified\":\"2025-07-31T15:09:47+00:00\",\"description\":\"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn't have a native enum type.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Enum Implementation Using Constants and Iota\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\",\"name\":\"Emily Johnson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"caption\":\"Emily Johnson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Go Enum Implementation Using Constants and Iota - Blog - Silicon Cloud","description":"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn't have a native enum type.","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:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/","og_locale":"en_US","og_type":"article","og_title":"Go Enum Implementation Using Constants and Iota","og_description":"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn't have a native enum type.","og_url":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-14T02:05:51+00:00","article_modified_time":"2025-07-31T15:09:47+00:00","author":"Emily Johnson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Emily Johnson","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/"},"author":{"name":"Emily Johnson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378"},"headline":"Go Enum Implementation Using Constants and Iota","datePublished":"2024-03-14T02:05:51+00:00","dateModified":"2025-07-31T15:09:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/"},"wordCount":127,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["constants","enum","Go language","Go programming","iota"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/","url":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/","name":"Go Enum Implementation Using Constants and Iota - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-14T02:05:51+00:00","dateModified":"2025-07-31T15:09:47+00:00","description":"Learn how to implement enumerations in Go using constant groups and the iota identifier, even though Go doesn't have a native enum type.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-go-keyword\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Enum Implementation Using Constants and Iota"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378","name":"Emily Johnson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","caption":"Emily Johnson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=4909"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4909\/revisions"}],"predecessor-version":[{"id":149622,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4909\/revisions\/149622"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=4909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=4909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=4909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}