Created
December 3, 2015 05:41
-
-
Save jordic/eeac12d80d50d412b830 to your computer and use it in GitHub Desktop.
go proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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