Skip to content

Instantly share code, notes, and snippets.

@junftnt
Forked from rolaveric/reverseProxy.go
Created May 4, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junftnt/00e813a61974d65ccc7287ef536b148c to your computer and use it in GitHub Desktop.
Save junftnt/00e813a61974d65ccc7287ef536b148c 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