Added Config.Address to allow the server to bind to a different IP address

This commit is contained in:
Tarcisio Gruppi
2019-01-11 16:16:56 -02:00
parent b1fdfcff37
commit 0f8d2d65d8
3 changed files with 4 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
{ {
"WebUrl": "https://domain.com", "WebUrl": "https://domain.com",
"Address": "",
"Port": 8080, "Port": 8080,
"ApiPrefix": "", "ApiPrefix": "",
"KeyFile": "", "KeyFile": "",

View File

@@ -2,6 +2,7 @@ package types
type Config struct { type Config struct {
WebUrl string WebUrl string
Address string
Port int Port int
ApiPrefix string ApiPrefix string
KeyFile string KeyFile string

View File

@@ -48,9 +48,9 @@ func main() {
} }
if config.CertFile == "" || config.KeyFile == "" { 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 { } 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())) log.Fatal(fmt.Errorf("failed to start server with: %s", err.Error()))
} }