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))) }