From b242fa87a86ee27ed0fccf925d49e13b9fe607ef Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Tue, 17 Sep 2019 13:57:52 -0400 Subject: fix config duration parsing --- main.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 81c69e4..a4192d9 100644 --- a/main.go +++ b/main.go @@ -18,15 +18,25 @@ func main() { } } +type duration struct { + time.Duration +} + +func (d *duration) UnmarshalText(text []byte) error { + var err error + d.Duration, err = time.ParseDuration(string(text)) + return err +} + type options struct { - BindAddress string `toml:"bind_address"` - CacheExpiry time.Duration `toml:"cache_expiry"` - UpstreamTimeout time.Duration `toml:"upstream_timeout"` - SourcehutUsername string `toml:"srht_username"` - SourcehutToken string `toml:"srht_token"` - GithubUsername string `toml:"github_username"` - GithubToken string `toml:"github_token"` - CanonicalPrefix string `toml:"canonical_prefix"` + BindAddress string `toml:"bind_address"` + CacheExpiry duration `toml:"cache_expiry"` + UpstreamTimeout duration `toml:"upstream_timeout"` + SourcehutUsername string `toml:"srht_username"` + SourcehutToken string `toml:"srht_token"` + GithubUsername string `toml:"github_username"` + GithubToken string `toml:"github_token"` + CanonicalPrefix string `toml:"canonical_prefix"` } func run() error { @@ -43,10 +53,13 @@ func run() error { return err } + log.Printf("caches expire after %s", opts.CacheExpiry.Duration) + log.Printf("upstream reqs time out after %s", opts.UpstreamTimeout.Duration) + cache := &PackageCache{ CanonicalPrefix: opts.CanonicalPrefix, - ExpireAfter: opts.CacheExpiry, - UpstreamTimeout: opts.UpstreamTimeout, + ExpireAfter: opts.CacheExpiry.Duration, + UpstreamTimeout: opts.UpstreamTimeout.Duration, Logger: log.New(os.Stdout, "", log.LstdFlags), Hosts: []RepoHost{ Sourcehut{Username: opts.SourcehutUsername, Token: opts.SourcehutToken}, -- cgit v1.2.3