title: Singleton http client
body: <p>I am creating a class with functions to call some apis, so far I have:</p>
  <pre><code>var client *http.Client
  
  func getClient() *http.Client {
      if client == nil {
          client = &amp;http.Client{
              Timeout: time.Second * 30,
              Transport: &amp;http.Transport{
                  Dial: (&amp;net.Dialer{
                  Timeout:   30 * time.Second,
                  KeepAlive: 30 * time.Second,
              }).Dial,
              TLSHandshakeTimeout: 10 * time.Second,
              },
          }
      }
      return client
  }
  </code></pre>
  <p>Then create a function that executes a call:</p>
  <pre><code>func CallRestApi(request Request) (response Response) {
      getClient()
      req, err := http.NewRequest(request.Method, url, bytes.NewBuffer(request.Params))
      
      resp, err := client.Do(req)
      ...
  }
  </code></pre>
  <p>I am not sure if this way I create a singleton <code>client</code> instance so that from any module that executes this function the instance will be used if it already exists.</p>