title: Golang Error: Undefined: http.NewSingleHostReverseProxy
body: <p>I tried building a simple program using Golang, here it is:</p>
  
  <pre><code>package main
  
  import (
          "net/http"
          "net/http/httputil"
          "log"
  )
  
  func main(){
  
          proxy := http.NewSingleHostReverseProxy( &amp;http.URL{Scheme:"http",Host:"www.google.com",Path:"/"})
  
          err := http.ListenAndServe(":8080", proxy)
          if err != nil {
                  log.Fatal("ListenAndServe: ", err.String())
          }
  }
  </code></pre>
  
  <p>Build:</p>
  
  <pre><code>go build myprogram.go
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>command-line-arguments
  ./myprogram.go:5: imported and not used: "net/http/httputil"
  ./myprogram.go:11: undefined: http.NewSingleHostReverseProxy
  ./myprogram.go:11: undefined: http.URL
  ./myprogram.go:15: err.String undefined (type error has no field or method String)
  </code></pre>
  
  <p>I noticed that http.NewSingleHostReverseProxy is in the "net/http/httputil" package, so why did I see such errors?
  Maybe I need a specific command to build it correctly?</p>
  
  <p><strong>EDIT</strong>
  Afterwords, here is the new working code:</p>
  
  <pre><code>package main
  
  import (
          "net/http"
          "net/http/httputil"
          "net/url"
          "log"
  )
  
  func main(){
  
          proxy := httputil.NewSingleHostReverseProxy( &amp;url.URL{Scheme:"http",Host:"www.google.com",Path:"/"})
  
          err := http.ListenAndServe(":8080", proxy)
          if err != nil {
                  log.Fatal("ListenAndServe: ", err)
          }
  }
  </code></pre>