diff options
-rw-r--r-- | main.go | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -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}, |