Skip to content

Instantly share code, notes, and snippets.

@jcelliott
Last active September 6, 2017 06:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcelliott/1cffc18e709fde368737 to your computer and use it in GitHub Desktop.
Save jcelliott/1cffc18e709fde368737 to your computer and use it in GitHub Desktop.
Reverse proxy using Go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
URL := &url.URL{Scheme: "http", Host: "example.com:5000"}
proxy := httputil.NewSingleHostReverseProxy(URL)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.URL)
proxy.ServeHTTP(w, r)
})
log.Println("Proxy server starting on port 5000")
log.Fatal(http.ListenAndServe(":5000", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment