From 87994855e1814f9b6be0675f9baa39333c6d95e0 Mon Sep 17 00:00:00 2001 From: l3uddz Date: Wed, 20 Apr 2022 17:27:33 +0100 Subject: [PATCH] feat: custom hosts (#149) --- README.md | 18 ++++++++++++++++++ cmd/autoscan/main.go | 25 +++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2624afb0..35ee81e5 100644 --- a/README.md +++ b/README.md @@ -506,6 +506,24 @@ targets: to: /data/ # path accessible by the Emby docker container (if applicable) ``` +## Other configuration options + +```yaml +# Specify the port to listen on (3030 is the default when not specified) +port: 3030 +``` + +```yaml +# Specify the host interface(s) to listen on (0.0.0.0 is the default when not specified) +host: + - 127.0.0.1 + - 172.19.185.13 + - 192.168.0.1:5959 +``` + +- If no port is specified, it will use the default port configured. +- This configuration option is only needed if you have a requirement to listen to multiple interfaces. + ## Other installation options ### Docker diff --git a/cmd/autoscan/main.go b/cmd/autoscan/main.go index e97793b0..0f2f05c3 100644 --- a/cmd/autoscan/main.go +++ b/cmd/autoscan/main.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "time" "github.com/alecthomas/kong" @@ -37,6 +38,7 @@ import ( type config struct { // General configuration + Host []string `yaml:"host"` Port int `yaml:"port"` MinimumAge time.Duration `yaml:"minimum-age"` ScanDelay time.Duration `yaml:"scan-delay"` @@ -171,6 +173,7 @@ func main() { MinimumAge: 10 * time.Minute, ScanDelay: 5 * time.Second, ScanStats: 1 * time.Hour, + Host: []string{""}, Port: 3030, } @@ -243,12 +246,22 @@ func main() { // http triggers router := getRouter(c, proc) - go func() { - log.Info().Msgf("Starting server on port %d", c.Port) - if err := http.ListenAndServe(fmt.Sprintf(":%d", c.Port), router); err != nil { - log.Fatal().Err(err).Msg("Failed starting web server") - } - }() + for _, h := range c.Host { + go func(host string) { + addr := host + if !strings.Contains(addr, ":") { + addr = fmt.Sprintf("%s:%d", host, c.Port) + } + + log.Info().Msgf("Starting server on %s", addr) + if err := http.ListenAndServe(addr, router); err != nil { + log.Fatal(). + Str("addr", addr). + Err(err). + Msg("Failed starting web server") + } + }(h) + } log.Info(). Int("manual", 1).