From fd18ba6527bf29e534ae12f7c88bcfbd69d2841c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Dec 2023 01:15:09 +0100 Subject: [PATCH] Change http config to sub element --- main.go | 2 +- ministream.toml | 3 ++- server/config.go | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index b6a5f2e..04fd1f9 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func main() { cfg := configFromCtx(c.Context) srv := server.NewServer(cfg) - srv.Addr = cfg.HTTPListenAddr + srv.Addr = cfg.HTTP.ListenAddr if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { return err } diff --git a/ministream.toml b/ministream.toml index 57d11b6..80b7322 100644 --- a/ministream.toml +++ b/ministream.toml @@ -3,7 +3,8 @@ # Env: MINISTREAM_SITENAME SiteName = "stream.example.org" +[HTTP] # HTTPListenAddr is which port the HTTP server will listen on. # Default: ":8080" -# Env: MINISTREAM_HTTPLISTENADDR +# Env: MINISTREAM_HTTP_LISTENADDR HTTPListenAddr = ":8080" diff --git a/server/config.go b/server/config.go index a52c6bc..a10c7c6 100644 --- a/server/config.go +++ b/server/config.go @@ -8,14 +8,20 @@ import ( ) type Config struct { - SiteName string `json:"siteName" toml:"siteName"` - HTTPListenAddr string `json:"httpListenAddr" toml:"HTTPListenAddr"` + SiteName string `toml:"siteName"` + HTTP ConfigHTTP `toml:"http"` +} + +type ConfigHTTP struct { + ListenAddr string `json:"ListenAddr" toml:"ListenAddr"` } func DefaultConfig() *Config { return &Config{ - SiteName: "ministream", - HTTPListenAddr: ":8080", + SiteName: "ministream", + HTTP: ConfigHTTP{ + ListenAddr: ":8080", + }, } } @@ -24,8 +30,8 @@ func (c *Config) OverrideFromEnv() { c.SiteName = siteName } - if httpAddr, ok := os.LookupEnv("MINISTREAM_HTTPLISTENADDR"); ok { - c.HTTPListenAddr = httpAddr + if httpAddr, ok := os.LookupEnv("MINISTREAM_HTTP_LISTENADDR"); ok { + c.HTTP.ListenAddr = httpAddr } }