title: Viper Automatic Environment Does Not Read from Environment
body: <p>I'm trying to complete a very simple example wherein I use <a href="https://github.com/spf13/viper" rel="nofollow noreferrer"><code>viper</code></a> to load configuration from environment variables. I have installed it in my project via <code>go get github.com/spf13/viper</code>, and the dependency is in my <code>go.mod</code>:</p>
  <pre><code>module github.com/naftulikay/viper-demo
  
  go 1.16
  
  require github.com/spf13/viper v1.7.1 // indirect
  </code></pre>
  <p>Here is my code, which does compile and run:</p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;github.com/spf13/viper&quot;
  )
  
  var config Config
  
  type Config struct {
      MyString string //`mapstructure:&quot;MY_STRING&quot;`
  }
  
  func main() {
      v := viper.New()
      v.AutomaticEnv()
  
      var err error
  
      err = v.Unmarshal(&amp;config)
  
      if err != nil {
          fmt.Printf(&quot;Unable to load config: %s\n&quot;, err)
      }
  
      fmt.Printf(&quot;%+v\n&quot;, &amp;config)
  }
  </code></pre>
  <p>I am setting environment variables to try to test different permutations of the environment variable name</p>
  <pre class="lang-sh prettyprint-override"><code>MY_STRING=a my_string=b MyString=c ./viper-demo
  </code></pre>
  <p>I've tried a lot of different things, removing the <code>mapstructure</code> annotation, changing its value, etc., but all I get when I execute is:</p>
  <pre><code>&amp;{MyString:}
  </code></pre>
  <p>I'm following the instructions from the README as well as other demos I've found online and it just seems like <code>viper</code> does not load environment variables.</p>
  <p>I feel like this is a very simple example, my requirements are mapping config to a struct, and fetching that config from environment variables. I may eventually start doing CLI flags and a config file, but environment variables are make-or-break for me, I need them to work.</p>
  <p>What am I missing?</p>