Skip to content

Instantly share code, notes, and snippets.

@ego008
Forked from rolaveric/reverseProxy.go
Created September 5, 2017 05:40
Show Gist options
  • Save ego008/481d782503811390cbc2d660168c41af to your computer and use it in GitHub Desktop.
Save ego008/481d782503811390cbc2d660168c41af to your computer and use it in GitHub Desktop.
Example of a reverse proxy written in Go
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