From e46e51643da219133bc64557e69138591d8c212b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 20 Oct 2022 17:28:03 +0200 Subject: [PATCH] config: port -> http-address The listen interface should be configurable too. --- README.md | 4 ++-- config/config.go | 8 ++++---- server.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5a36c9f..89ec109 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Code for [10man](https://hub.xenrox.net/~xenrox/10man/) API. Your config file should be placed at `/etc/10man-api/config`. ``` -# Port -port 8080 +# http listen address +http-address 127.0.0.1:8080 # Connection string for the database (required) connection-string postgresql://user:pass@localhost/db?sslmode=disable # Comma separated list of steamID64 for users that should become an admin diff --git a/config/config.go b/config/config.go index 14b600e..db3293c 100644 --- a/config/config.go +++ b/config/config.go @@ -8,7 +8,7 @@ import ( ) type Config struct { - Port string + HTTPAddress string DBConnectionString string LogLevel string Admins []string @@ -23,12 +23,12 @@ func ReadConfig(path string) (*Config, error) { config := new(Config) // Set default values - config.Port = "8080" + config.HTTPAddress = "127.0.0.1:8080" config.LogLevel = "info" - d := cfg.Get("port") + d := cfg.Get("http-address") if d != nil { - if err := d.ParseParams(&config.Port); err != nil { + if err := d.ParseParams(&config.HTTPAddress); err != nil { return nil, err } } diff --git a/server.go b/server.go index 3e7f232..e2922df 100644 --- a/server.go +++ b/server.go @@ -50,7 +50,7 @@ func main() { http.Handle("/query", srv) go func() { - logger.Fatal(http.ListenAndServe(":"+cfg.Port, nil)) + logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, nil)) }() shutdown(<-sigs, db, logger) -- 2.44.0