-
-
Save stevenferrer/1a47b90b1c0a7b9c93c64ca2de4a5bd9 to your computer and use it in GitHub Desktop.
Golang reverse proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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