Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created February 23, 2014 06:25
Show Gist options
  • Save rolaveric/9167845 to your computer and use it in GitHub Desktop.
Save rolaveric/9167845 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