-
-
Save ego008/29d580a7939d07348d175b2a822dbb25 to your computer and use it in GitHub Desktop.
Reverse proxy using Go
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" | |
"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