4 files changed,
8 insertions(+),
32 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-15 15:44:39 +0200
Change ID:
xwpuoqqznvkpmxrsxyntvktprlkqloox
Parent:
77d86b7
M
internal/config/config.go
@@ -6,6 +6,7 @@ "fmt"
"os" "path/filepath" "strings" + "time" "gopkg.in/yaml.v2" )@@ -41,9 +42,10 @@ Keys []string `yaml:"keys"`
} type MirrorConfig struct { - Enable bool `yaml:"enable"` - Interval string `yaml:"interval"` - GithubToken string `yaml:"github_token"` + Enable bool `yaml:"enable"` + Interval time.Duration `yaml:"interval"` + GithubToken string `yaml:"github_token"` +} } type Config struct {@@ -138,8 +140,8 @@ }
} // mirroring - if c.Mirror.Interval == "" { - c.Mirror.Interval = "8h" + if c.Mirror.Interval == 0 { + c.Mirror.Interval = 8 * time.Hour } }
M
internal/config/validate.go
@@ -4,14 +4,12 @@ import (
"errors" "fmt" "strings" - "time" ) func (c Config) validate() error { var errs []error if c.Meta.Host == "" { - // TODO: actually it should be a warning, host only used for go-import tag errs = append(errs, errors.New("meta.host is required")) }@@ -38,12 +36,6 @@ }
if !isFileExists(c.SSH.HostKey) { errs = append(errs, fmt.Errorf("ssh.host_key seems to be an invalid path")) - } - } - - if c.Mirror.Enable { - if _, err := time.ParseDuration(c.Mirror.Interval); err != nil { - errs = append(errs, fmt.Errorf("mirror.interval: invalid duration format: %w", err)) } }
M
internal/config/validate_test.go
@@ -108,18 +108,6 @@ HostKey: "/somewhere",
}, }, }, - { - name: "invalid mirror.interval duration format", - expected: "mirror.interval: invalid duration", - c: Config{ - Meta: MetaConfig{Host: "example.com"}, - Repo: RepoConfig{Dir: t.TempDir()}, - Mirror: MirrorConfig{ - Enable: true, - Interval: "asdf", - }, - }, - }, } for _, tt := range tests {
M
internal/mirror/mirror.go
@@ -27,13 +27,7 @@ }
} func (w *Worker) Start(ctx context.Context) error { - interval, err := time.ParseDuration(w.c.Mirror.Interval) - if err != nil { - slog.Error("couldn't parse interval time", "err", err) - return err - } - - ticker := time.NewTicker(interval) + ticker := time.NewTicker(w.c.Mirror.Interval) defer ticker.Stop() for {