From 346b7ecd32d841e37280e4f631969e4fc3726971 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Tue, 3 Nov 2015 14:31:23 -0800 Subject: [PATCH] added ability to specify port via env --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6e26b7e..148d7e7 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,10 @@ import ( "fmt" "net/http" "os" + "strconv" ) const usage = "servetls " -const port = 8443 func main() { if len(os.Args) != 3 { @@ -18,6 +18,15 @@ func main() { http.HandleFunc("/", handler) + port := 8443 + if os.Getenv("PORT") != "" { + p, err := strconv.Atoi(os.Getenv("PORT")) + if err != nil { + fmt.Fprintf(os.Stderr, "could not parse PORT variable: %s\n", os.Getenv("PORT")) + os.Exit(1) + } + port = p + } addr := fmt.Sprintf(":%d", port) fmt.Printf("serving on %s", addr) err := http.ListenAndServeTLS(addr, cert, key, nil)