Skip to content

Instantly share code, notes, and snippets.

@stevenferrer
Forked from montanaflynn/proxy.go
Created July 26, 2017 05:54
Show Gist options
  • Save stevenferrer/1a47b90b1c0a7b9c93c64ca2de4a5bd9 to your computer and use it in GitHub Desktop.
Save stevenferrer/1a47b90b1c0a7b9c93c64ca2de4a5bd9 to your computer and use it in GitHub Desktop.
Golang reverse proxy
package main
import (
"log"
"net/http"
"net/http/httputil"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
director := func(req *http.Request) {
req = r
req.URL.Scheme = "http"
req.URL.Host = r.Host
}
proxy := &httputil.ReverseProxy{Director: director}
proxy.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe(":8181", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment