title: Unable to read environment variables outside a function in go with os.Getenv("KEY")
body: <p>I am a newbie to go, while using sling to make api calls to an external service
  when I do
  <code>var api = sling.New().Base(os.Getenv(&quot;BASE_URL&quot;))</code>
  the value comes as &quot;&quot;</p>
  <p>but when I do the same in a function to debug</p>
  <pre><code>var api = sling.New().Base(os.Getenv(&quot;BASE_URL&quot;)) // raw url is blank
  var api2=os.Getenv(&quot;BASE_URL&quot;)
  type Params struct{
  //params defined
  }
  
  func GetInfo(){
  
  //params set
  
  log.debug(&quot;base url:&quot;,os.Getenv(&quot;BASE_URL&quot;)) // prints &quot;www.example.com/&quot; as set in .env file
  log.debug(&quot;base url from outside the function :&quot;,api2) //also empty
      if _, err := api.New().Get(&quot;trailingURL/rest&quot;).QueryStruct(params).ReceiveSuccess(response); err != nil || !response.Successful() {
          
          return false
      } // fails as base url is not set
  
  }
  </code></pre>
  <p>where am I going wrong?</p>