Last active
September 6, 2017 06:58
-
-
Save jcelliott/1cffc18e709fde368737 to your computer and use it in GitHub Desktop.
Reverse proxy using Go
This file contains 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" | |
"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