{"id":291,"date":"2026-04-30T09:00:00","date_gmt":"2026-04-30T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/"},"modified":"2026-10-10T21:20:59","modified_gmt":"2026-10-10T15:50:59","slug":"go-environment-variables-config","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/","title":{"rendered":"Go Environment Variables for App Configuration"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go environment variables let you configure a program from the outside. So the same binary runs on your laptop, in testing and in production. In this post, you will read variables safely, add defaults, convert text to numbers and build a small config loader. Each idea comes with a short example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every value arrives as text, so the <code>strconv<\/code> helpers from <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings explained with examples<\/a> will be useful. We will also return clear errors, just like in <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">error handling in Go for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Environment Variables?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An environment variable is a named piece of text that the operating system passes to every program it starts. For example, <code>PORT=8080<\/code> or <code>DATABASE_URL=postgres:\/\/localhost\/shop<\/code>. Your program reads Go environment variables at startup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a hotel key card. The room is the same for every guest, but each card opens it with different settings. Similarly, one compiled program can behave differently on each server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This idea comes from the twelve-factor app guidelines. In short, keep configuration out of your code, so you never commit passwords to Git.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Reading a Variable: Getenv vs LookupEnv<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>fmt.Printf(\"%q\\n\", os.Getenv(\"NOT_SET\")) \/\/ \"\"\n\nv, ok := os.LookupEnv(\"NOT_SET\")\nfmt.Printf(\"%q %v\\n\", v, ok) \/\/ \"\" false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>os.Getenv<\/code> returns an empty string when a variable is missing. However, it cannot tell &#8220;missing&#8221; apart from &#8220;set to empty&#8221;. So use <code>os.LookupEnv<\/code> when that difference matters, because it also returns a boolean.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A Helper with a Default<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func getEnv(key, fallback string) string {\n\tif v, ok := os.LookupEnv(key); ok {\n\t\treturn v\n\t}\n\treturn fallback\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This tiny helper for Go environment variables appears in almost every service. It returns the real value when one exists, or a sensible default otherwise.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Converting Go Environment Variables to Numbers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every value is a string, even <code>PORT=9000<\/code>. Therefore, convert it with <code>strconv<\/code> and check the error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>port, err := strconv.Atoi(getEnv(\"PORT\", \"8080\"))\nif err != nil {\n\treturn Config{}, fmt.Errorf(\"PORT must be a number: %w\", err)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, use <code>strconv.ParseBool<\/code> for flags like <code>DEBUG=true<\/code> and <code>time.ParseDuration<\/code> for values like <code>TIMEOUT=5s<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building a Config Loader<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The best pattern is to read everything once at startup into a struct. The diagram below shows the flow from the environment to your app.<\/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-environment-variables-config-diagram-1024x640.png\" alt=\"Go Environment Variables diagram showing variables loaded, defaulted, converted and validated into a Config struct\" class=\"wp-image-273\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Load reads each variable, applies defaults, converts types and validates required values before main starts the app.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type Config struct {\n\tPort    int\n\tDBURL   string\n\tDebug   bool\n\tTimeout time.Duration\n}\n\nfunc Load() (Config, error) {\n\tport, err := strconv.Atoi(getEnv(\"PORT\", \"8080\"))\n\tif err != nil {\n\t\treturn Config{}, fmt.Errorf(\"PORT must be a number: %w\", err)\n\t}\n\tdebug, err := strconv.ParseBool(getEnv(\"DEBUG\", \"false\"))\n\tif err != nil {\n\t\treturn Config{}, fmt.Errorf(\"DEBUG must be true or false: %w\", err)\n\t}\n\ttimeout, err := time.ParseDuration(getEnv(\"TIMEOUT\", \"5s\"))\n\tif err != nil {\n\t\treturn Config{}, fmt.Errorf(\"TIMEOUT: %w\", err)\n\t}\n\tdbURL := os.Getenv(\"DATABASE_URL\")\n\tif dbURL == \"\" {\n\t\treturn Config{}, fmt.Errorf(\"DATABASE_URL is required\")\n\t}\n\treturn Config{Port: port, DBURL: dbURL, Debug: debug, Timeout: timeout}, nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then call it at the top of <code>main<\/code> and stop early on any problem.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cfg, err := Load()\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", cfg)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ DATABASE_URL=postgres:\/\/localhost\/shop PORT=9000 DEBUG=true go run .\n{Port:9000 DBURL:postgres:\/\/localhost\/shop Debug:true Timeout:5s}\n\n$ go run .\n2026\/08\/22 09:00:00 DATABASE_URL is required<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Failing fast at startup is much better than crashing later during a customer request. As a result, configuration mistakes show up the moment you deploy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting Go Environment Variables in Tests<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func TestLoad(t *testing.T) {\n\tt.Setenv(\"DATABASE_URL\", \"postgres:\/\/test\")\n\tt.Setenv(\"PORT\", \"9999\")\n\tcfg, err := Load()\n\tif err != nil || cfg.Port != 9999 {\n\t\tt.Fatalf(\"got %+v, %v\", cfg, err)\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>t.Setenv<\/code> changes a variable only for that test and restores it afterwards. You learned the rest of this pattern in <a href=\"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/\">Go unit testing for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Environment Variables<\/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>strconv.Atoi: parsing &#8220;abc&#8221;: invalid syntax<\/td><td>PORT holds text, not a number.<\/td><td>Validate and return a clear error.<\/td><\/tr><tr><td>App starts with an empty database URL<\/td><td><code>Getenv<\/code> hid the missing value.<\/td><td>Check required values in <code>Load<\/code>.<\/td><\/tr><tr><td>Values in a .env file are ignored<\/td><td>Go does not read .env files on its own.<\/td><td>Export them in the shell or use a loader library.<\/td><\/tr><tr><td>Secrets appear in logs<\/td><td>The whole config was printed.<\/td><td>Mask secret fields before logging.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Configuration questions appear in many backend 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:\/\/pkg.go.dev\/os#LookupEnv\">os package: Getenv and LookupEnv<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/strconv\">strconv package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/testing#T.Setenv\">testing package: T.Setenv<\/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 environment variables configure a program without changing code.<\/li>\n\n\n\n<li><code>LookupEnv<\/code> tells &#8220;missing&#8221; apart from &#8220;empty&#8221;.<\/li>\n\n\n\n<li>Every value is text, so convert it with <code>strconv<\/code>.<\/li>\n\n\n\n<li>Load everything into a Config struct once and fail fast.<\/li>\n\n\n\n<li>Use <code>t.Setenv<\/code> to set variables safely in tests.<\/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\">Your app now reads its settings from the environment. Next, we will build command line tools that accept options with the flag package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/\">Go Flag Package: Build Command Line Tools<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go environment variables let you configure a program from the outside. So the same binary runs on your laptop, in testing and in production.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":272,"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":[57,11,23,21],"swapz_series":[],"class_list":["post-291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-configuration","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 Environment Variables for App Configuration<\/title>\n<meta name=\"description\" content=\"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.\" \/>\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-environment-variables-config\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Environment Variables for App Configuration\" \/>\n<meta property=\"og:description\" content=\"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-30T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Environment Variables for App Configuration\",\"datePublished\":\"2026-04-30T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/\"},\"wordCount\":600,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-environment-variables-config-featured.png\",\"keywords\":[\"Go Configuration\",\"Go Lang\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/\",\"name\":\"Go Environment Variables for App Configuration\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-environment-variables-config-featured.png\",\"datePublished\":\"2026-04-30T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:59+00:00\",\"description\":\"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-environment-variables-config-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-environment-variables-config-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Environment Variables featured image: cards for reading values, converting text and a config struct\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-environment-variables-config\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Environment Variables for App Configuration\"}]},{\"@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 Environment Variables for App Configuration","description":"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.","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-environment-variables-config\/","og_locale":"en_US","og_type":"article","og_title":"Go Environment Variables for App Configuration","og_description":"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.","og_url":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-30T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:59+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Environment Variables for App Configuration","datePublished":"2026-04-30T03:30:00+00:00","dateModified":"2026-10-10T15:50:59+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/"},"wordCount":600,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-featured.png","keywords":["Go Configuration","Go Lang","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/","url":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/","name":"Go Environment Variables for App Configuration","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-featured.png","datePublished":"2026-04-30T03:30:00+00:00","dateModified":"2026-10-10T15:50:59+00:00","description":"Learn Go environment variables with simple examples: Getenv vs LookupEnv, default values, parsing numbers and building a safe config loader.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-environment-variables-config-featured.png","width":2400,"height":1260,"caption":"Go Environment Variables featured image: cards for reading values, converting text and a config struct"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Environment Variables for App Configuration"}]},{"@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\/291","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=291"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":306,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/291\/revisions\/306"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/272"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=291"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}