From 0f8d2d65d8038c5886d0bdc1f953f5b6ade1b2d0 Mon Sep 17 00:00:00 2001 From: Tarcisio Gruppi Date: Fri, 11 Jan 2019 16:16:56 -0200 Subject: [PATCH] Added Config.Address to allow the server to bind to a different IP address --- config.json.sample | 1 + core/model/types/config.go | 1 + core/server.go | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config.json.sample b/config.json.sample index 591aeef..a77a167 100644 --- a/config.json.sample +++ b/config.json.sample @@ -1,5 +1,6 @@ { "WebUrl": "https://domain.com", + "Address": "", "Port": 8080, "ApiPrefix": "", "KeyFile": "", diff --git a/core/model/types/config.go b/core/model/types/config.go index 58c28c0..65e5842 100644 --- a/core/model/types/config.go +++ b/core/model/types/config.go @@ -2,6 +2,7 @@ package types type Config struct { WebUrl string + Address string Port int ApiPrefix string KeyFile string diff --git a/core/server.go b/core/server.go index 1dfc574..b9e8b90 100644 --- a/core/server.go +++ b/core/server.go @@ -48,9 +48,9 @@ func main() { } if config.CertFile == "" || config.KeyFile == "" { - err = http.ListenAndServe(":"+strconv.Itoa(config.Port), app.MakeHandler()) + err = http.ListenAndServe(config.Address+":"+strconv.Itoa(config.Port), app.MakeHandler()) } else { - err = http.ListenAndServeTLS(":"+strconv.Itoa(config.Port), config.CertFile, config.KeyFile, app.MakeHandler()) + err = http.ListenAndServeTLS(config.Address+":"+strconv.Itoa(config.Port), config.CertFile, config.KeyFile, app.MakeHandler()) } log.Fatal(fmt.Errorf("failed to start server with: %s", err.Error())) }