-
-
Save ego008/481d782503811390cbc2d660168c41af to your computer and use it in GitHub Desktop.
Example of a reverse proxy written in 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
import ( | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"fmt" | |
) | |
func main() { | |
// New functionality written in Go | |
http.HandleFunc("/new", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "New function") | |
}) | |
// Anything we don't do in Go, we pass to the old platform | |
u, _ := url.Parse("http://old.mydomain/") | |
http.Handle("/", httputil.NewSingleHostReverseProxy(u)) | |
// Start the server | |
http.ListenAndServe(":8080", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment