summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-09-17 13:57:52 -0400
committerBen Burwell <ben@benburwell.com>2019-09-17 13:57:52 -0400
commitb242fa87a86ee27ed0fccf925d49e13b9fe607ef (patch)
tree5104a09d1ccfe6dce49778457e850ccd4d52aee8
parent7a96c50022405b5c01c8b3a58966655dcb5bf754 (diff)
fix config duration parsing0.1.2
-rw-r--r--main.go33
1 files 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},