Skip to content

Instantly share code, notes, and snippets.

@dsdstudio
Created March 31, 2015 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsdstudio/fcbcd3d155de7177d3b2 to your computer and use it in GitHub Desktop.
Save dsdstudio/fcbcd3d155de7177d3b2 to your computer and use it in GitHub Desktop.
simple reverse proxy server
package main
import (
"log"
"strings"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {
u, _ := url.Parse("http://127.0.0.1:9090")
http.HandleFunc("/proxy", func(w http.ResponseWriter, r *http.Request) {
r.RequestURI = strings.Join(strings.SplitAfter(r.RequestURI, "/proxy"), "")
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.ServeHTTP(w, r)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.ServeHTTP(w, r)
})
err := http.ListenAndServe("127.0.0.1:80", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment