From 6c4af147d5dc08cb1fceccdd9b5b92a22189e45a Mon Sep 17 00:00:00 2001 From: Max Claus Nunes Date: Fri, 11 Nov 2016 16:33:54 -0200 Subject: [PATCH] Allow change the server bind address --- main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index edcb83f..91bc3e6 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,18 @@ import ( // version is definded during the build var version string +func getServiceAddress() string { + if env := os.Getenv("VIRTUAL_PORT"); env != "" { + return ":" + env + } + + if env := os.Getenv("HTTP_PORT"); env != "" { + return ":" + env + } + + return ":3000" +} + func handleSubmit(w http.ResponseWriter, r *http.Request, defaults []string) { var d struct{ Args []string } @@ -62,6 +74,7 @@ func main() { http.NotFound(w, r) }) - log.Println("Starting server") - log.Fatal(http.ListenAndServe(":8080", nil)) + addrs := getServiceAddress() + log.Printf("Starting server at %s\n", addrs) + log.Fatal(http.ListenAndServe(addrs, nil)) }