Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Last active January 17, 2021 15:37
Show Gist options
  • Save montanaflynn/304aa58b188f036204af to your computer and use it in GitHub Desktop.
Save montanaflynn/304aa58b188f036204af 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))
}
@dotqi
Copy link

dotqi commented Sep 9, 2018

How can I catch 502 errors and rewrite errors? Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment