Change http config to sub element
This commit is contained in:
parent
8cb0ede570
commit
fd18ba6527
2
main.go
2
main.go
@ -32,7 +32,7 @@ func main() {
|
|||||||
cfg := configFromCtx(c.Context)
|
cfg := configFromCtx(c.Context)
|
||||||
|
|
||||||
srv := server.NewServer(cfg)
|
srv := server.NewServer(cfg)
|
||||||
srv.Addr = cfg.HTTPListenAddr
|
srv.Addr = cfg.HTTP.ListenAddr
|
||||||
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
# Env: MINISTREAM_SITENAME
|
# Env: MINISTREAM_SITENAME
|
||||||
SiteName = "stream.example.org"
|
SiteName = "stream.example.org"
|
||||||
|
|
||||||
|
[HTTP]
|
||||||
# HTTPListenAddr is which port the HTTP server will listen on.
|
# HTTPListenAddr is which port the HTTP server will listen on.
|
||||||
# Default: ":8080"
|
# Default: ":8080"
|
||||||
# Env: MINISTREAM_HTTPLISTENADDR
|
# Env: MINISTREAM_HTTP_LISTENADDR
|
||||||
HTTPListenAddr = ":8080"
|
HTTPListenAddr = ":8080"
|
||||||
|
@ -8,14 +8,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
SiteName string `json:"siteName" toml:"siteName"`
|
SiteName string `toml:"siteName"`
|
||||||
HTTPListenAddr string `json:"httpListenAddr" toml:"HTTPListenAddr"`
|
HTTP ConfigHTTP `toml:"http"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConfigHTTP struct {
|
||||||
|
ListenAddr string `json:"ListenAddr" toml:"ListenAddr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
SiteName: "ministream",
|
SiteName: "ministream",
|
||||||
HTTPListenAddr: ":8080",
|
HTTP: ConfigHTTP{
|
||||||
|
ListenAddr: ":8080",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,8 +30,8 @@ func (c *Config) OverrideFromEnv() {
|
|||||||
c.SiteName = siteName
|
c.SiteName = siteName
|
||||||
}
|
}
|
||||||
|
|
||||||
if httpAddr, ok := os.LookupEnv("MINISTREAM_HTTPLISTENADDR"); ok {
|
if httpAddr, ok := os.LookupEnv("MINISTREAM_HTTP_LISTENADDR"); ok {
|
||||||
c.HTTPListenAddr = httpAddr
|
c.HTTP.ListenAddr = httpAddr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user