From da5c01ccce1d9c5867c7f4b7e654d262a502413e Mon Sep 17 00:00:00 2001 From: Kenneth Date: Mon, 2 Dec 2024 17:15:39 +0000 Subject: [PATCH] feat: allow port to be set in config --- internal/service/config.go | 7 +++++++ main.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/service/config.go b/internal/service/config.go index 65ac5ef..56155d8 100644 --- a/internal/service/config.go +++ b/internal/service/config.go @@ -7,12 +7,15 @@ import ( ) type Config struct { + Port int `json:"port"` DatabasePath string `json:"databasePath"` TemplateDirectoryPath string `json:"templateDirectoryPath"` HostKeyDirectoryPath string `json:"hostKeyDirectoryPath"` HostName string `json:"hostName"` } +const defaultPort = 8080 + func ReadConfigFrom(reader io.Reader) (Config, error) { var config Config err := json.NewDecoder(reader).Decode(&config) @@ -35,5 +38,9 @@ func ReadConfigFrom(reader io.Reader) (Config, error) { return Config{}, err } + if config.Port == 0 { + config.Port = defaultPort + } + return config, nil } diff --git a/main.go b/main.go index 87e6a7e..63f4f99 100644 --- a/main.go +++ b/main.go @@ -103,5 +103,5 @@ func main() { _ = c.NoContent(http.StatusInternalServerError) } - apiServer.Logger.Fatal(apiServer.Start(":8080")) + apiServer.Logger.Fatal(apiServer.Start(fmt.Sprintf(":%d", config.Port))) }