diff options
author | Alan Pearce | 2024-05-20 18:25:25 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-20 18:25:25 +0200 |
commit | 202317df1dba891654bf749c3720fbd602df04ff (patch) | |
tree | c536ace4120e62602a142959a85e92d61317a1c2 /internal/config/config.go | |
parent | 0f5508013d776f8806a87957f80e74c7f74c72eb (diff) | |
download | searchix-202317df1dba891654bf749c3720fbd602df04ff.tar.lz searchix-202317df1dba891654bf749c3720fbd602df04ff.tar.zst searchix-202317df1dba891654bf749c3720fbd602df04ff.zip |
fix: nix cannot read date/time TOML values from default config
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 3947d18..9ab7ab5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -62,7 +62,30 @@ func mustURL(in string) (u URL) { return u } -func mustLocalTime(in string) (time toml.LocalTime) { +// this type is necessary as nix's `fromTOML` doesn't support TOML date/time formats +type LocalTime struct { + toml.LocalTime +} + +func (t *LocalTime) MarshalText() ([]byte, error) { + b, err := t.LocalTime.MarshalText() + if err != nil { + return nil, errors.WithMessage(err, "could not marshal time value") + } + + return b, nil +} + +func (t *LocalTime) UnmarshalText(in []byte) (err error) { + err = t.LocalTime.UnmarshalText(in) + if err != nil { + return errors.WithMessage(err, "could not parse time value") + } + + return nil +} + +func mustLocalTime(in string) (time LocalTime) { err := time.UnmarshalText([]byte(in)) if err != nil { panic(errors.Errorf("Could not parse time: %s", in)) @@ -85,7 +108,7 @@ type Web struct { type Importer struct { Sources map[string]*Source Timeout Duration - UpdateAt toml.LocalTime + UpdateAt LocalTime } type Config struct { |