Created
August 15, 2014 05:27
-
-
Save Xe/45eb286d532c29d925e0 to your computer and use it in GitHub Desktop.
12 factor HTTP proxy
This file contains hidden or 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" | |
| "net/url" | |
| "os" | |
| "time" | |
| ) | |
| func main() { | |
| var src, dst string | |
| dst = os.Getenv("DESTINATION") | |
| src = ":" + os.Getenv("PORT") | |
| u, e := url.Parse(dst) | |
| if e != nil { | |
| log.Fatal("Bad destination.") | |
| } | |
| h := httputil.NewSingleHostReverseProxy(u) | |
| s := &http.Server{ | |
| Addr: src, | |
| Handler: h, | |
| ReadTimeout: 10 * time.Second, | |
| WriteTimeout: 10 * time.Second, | |
| MaxHeaderBytes: 1 << 20, | |
| } | |
| log.Fatal(s.ListenAndServe()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment