diff options
author | Alan Pearce | 2024-05-13 21:50:14 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-13 22:25:46 +0200 |
commit | 6b40e0c0fa90f11be14a93f1d6275779fd645cac (patch) | |
tree | 0df5bea87242450829ca441d235c077a0e09a149 /internal/config/config.go | |
parent | 2722f24af87f437ed9fcb8cc743ad1784141fd3a (diff) | |
download | searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.lz searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.zst searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.zip |
refactor: combine import and web server into one binary
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index c3a5a90..ec04a2c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -26,6 +26,19 @@ func (u *URL) UnmarshalText(text []byte) (err error) { return nil } +type Duration struct { + time.Duration +} + +func (d *Duration) UnmarshalText(text []byte) (err error) { + d.Duration, err = time.ParseDuration(string(text)) + if err != nil { + return errors.WithMessagef(err, "could not parse duration %s", string(text)) + } + + return nil +} + func mustURL(in string) (u URL) { var err error u.URL, err = url.Parse(in) @@ -36,6 +49,15 @@ func mustURL(in string) (u URL) { return u } +func mustLocalTime(in string) (time toml.LocalTime) { + err := time.UnmarshalText([]byte(in)) + if err != nil { + panic(errors.Errorf("Could not parse time: %s", in)) + } + + return +} + type Web struct { ContentSecurityPolicy CSP ListenAddress string @@ -48,8 +70,9 @@ type Web struct { } type Importer struct { - Sources map[string]*Source - Timeout time.Duration + Sources map[string]*Source + Timeout Duration + UpdateAt toml.LocalTime } type Config struct { @@ -73,7 +96,8 @@ var defaultConfig = Config{ }, }, Importer: &Importer{ - Timeout: 30 * time.Minute, + Timeout: Duration{30 * time.Minute}, + UpdateAt: mustLocalTime("04:00:00"), Sources: map[string]*Source{ "nixos": { Name: "NixOS", |