Skip to content

Instantly share code, notes, and snippets.

@Xe
Created August 15, 2014 05:27
Show Gist options
  • Select an option

  • Save Xe/45eb286d532c29d925e0 to your computer and use it in GitHub Desktop.

Select an option

Save Xe/45eb286d532c29d925e0 to your computer and use it in GitHub Desktop.
12 factor HTTP proxy
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