Created
December 1, 2016 12:54
-
-
Save olostan/cee61b76dd426de392f6df2d372aa9e8 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"fmt" | |
) | |
type proxyHandler struct { | |
binding string | |
} | |
func (p *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
director := func(req *http.Request) { | |
req = r | |
req.URL.Scheme = "http" | |
req.URL.Host = "10.20.20.116"+p.binding | |
} | |
proxy := &httputil.ReverseProxy{Director: director} | |
proxy.ServeHTTP(w, r) | |
} | |
func main() { | |
runner := func(binding string) { | |
fmt.Printf("Listening on %s\n", binding); | |
log.Fatal(http.ListenAndServe(binding, &proxyHandler{binding})); | |
}; | |
go runner(":8180"); | |
go runner(":80"); | |
select{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment