Skip to content

Instantly share code, notes, and snippets.

@jordic
Created December 3, 2015 05:41
Show Gist options
  • Save jordic/eeac12d80d50d412b830 to your computer and use it in GitHub Desktop.
Save jordic/eeac12d80d50d412b830 to your computer and use it in GitHub Desktop.
go proxy
/*
url1, _ := url.Parse("https://www.google.es")
url2, _ := url.Parse("http://www.mon.cat")
a := &proxy{
entry: map[string]*httputil.ReverseProxy{
"google": httputil.NewSingleHostReverseProxy(url1),
"mon": httputil.NewSingleHostReverseProxy(url2),
},
}
http.Handle("/", a)
http.ListenAndServe(":8888", nil)
*/
type proxy struct {
entry map[string]*httputil.ReverseProxy
}
func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("Request %s/n", r.Host)
for k, v := range p.entry {
if strings.HasPrefix(r.Host, k) {
r.Host = "www.google.es"
v.ServeHTTP(w, r)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment