all repos

mugit @ b7d443e

馃惍 git server that your cow will love
4 files changed, 8 insertions(+), 32 deletions(-)
config: parse interval directly as time.Duration
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-15 15:44:39 +0200
Authored at: 2026-02-15 15:26:55 +0200
Change ID: xwpuoqqznvkpmxrsxyntvktprlkqloox
Parent: 77d86b7
M internal/config/config.go
路路路
        6
        6
         	"os"

      
        7
        7
         	"path/filepath"

      
        8
        8
         	"strings"

      
        
        9
        +	"time"

      
        9
        10
         

      
        10
        11
         	"gopkg.in/yaml.v2"

      
        11
        12
         )

      路路路
        41
        42
         }

      
        42
        43
         

      
        43
        44
         type MirrorConfig struct {

      
        44
        
        -	Enable      bool   `yaml:"enable"`

      
        45
        
        -	Interval    string `yaml:"interval"`

      
        46
        
        -	GithubToken string `yaml:"github_token"`

      
        
        45
        +	Enable      bool          `yaml:"enable"`

      
        
        46
        +	Interval    time.Duration `yaml:"interval"`

      
        
        47
        +	GithubToken string        `yaml:"github_token"`

      
        
        48
        +}

      
        47
        49
         }

      
        48
        50
         

      
        49
        51
         type Config struct {

      路路路
        138
        140
         	}

      
        139
        141
         

      
        140
        142
         	// mirroring

      
        141
        
        -	if c.Mirror.Interval == "" {

      
        142
        
        -		c.Mirror.Interval = "8h"

      
        
        143
        +	if c.Mirror.Interval == 0 {

      
        
        144
        +		c.Mirror.Interval = 8 * time.Hour

      
        143
        145
         	}

      
        144
        146
         }

      
        145
        147
         

      
M internal/config/validate.go
路路路
        4
        4
         	"errors"

      
        5
        5
         	"fmt"

      
        6
        6
         	"strings"

      
        7
        
        -	"time"

      
        8
        7
         )

      
        9
        8
         

      
        10
        9
         func (c Config) validate() error {

      
        11
        10
         	var errs []error

      
        12
        11
         

      
        13
        12
         	if c.Meta.Host == "" {

      
        14
        
        -		// TODO: actually it should be a warning, host only used for go-import tag

      
        15
        13
         		errs = append(errs, errors.New("meta.host is required"))

      
        16
        14
         	}

      
        17
        15
         

      路路路
        38
        36
         

      
        39
        37
         		if !isFileExists(c.SSH.HostKey) {

      
        40
        38
         			errs = append(errs, fmt.Errorf("ssh.host_key seems to be an invalid path"))

      
        41
        
        -		}

      
        42
        
        -	}

      
        43
        
        -

      
        44
        
        -	if c.Mirror.Enable {

      
        45
        
        -		if _, err := time.ParseDuration(c.Mirror.Interval); err != nil {

      
        46
        
        -			errs = append(errs, fmt.Errorf("mirror.interval: invalid duration format: %w", err))

      
        47
        39
         		}

      
        48
        40
         	}

      
        49
        41
         

      
M internal/config/validate_test.go
路路路
        108
        108
         				},

      
        109
        109
         			},

      
        110
        110
         		},

      
        111
        
        -		{

      
        112
        
        -			name:     "invalid mirror.interval duration format",

      
        113
        
        -			expected: "mirror.interval: invalid duration",

      
        114
        
        -			c: Config{

      
        115
        
        -				Meta: MetaConfig{Host: "example.com"},

      
        116
        
        -				Repo: RepoConfig{Dir: t.TempDir()},

      
        117
        
        -				Mirror: MirrorConfig{

      
        118
        
        -					Enable:   true,

      
        119
        
        -					Interval: "asdf",

      
        120
        
        -				},

      
        121
        
        -			},

      
        122
        
        -		},

      
        123
        111
         	}

      
        124
        112
         

      
        125
        113
         	for _, tt := range tests {

      
M internal/mirror/mirror.go
路路路
        27
        27
         }

      
        28
        28
         

      
        29
        29
         func (w *Worker) Start(ctx context.Context) error {

      
        30
        
        -	interval, err := time.ParseDuration(w.c.Mirror.Interval)

      
        31
        
        -	if err != nil {

      
        32
        
        -		slog.Error("couldn't parse interval time", "err", err)

      
        33
        
        -		return err

      
        34
        
        -	}

      
        35
        
        -

      
        36
        
        -	ticker := time.NewTicker(interval)

      
        
        30
        +	ticker := time.NewTicker(w.c.Mirror.Interval)

      
        37
        31
         	defer ticker.Stop()

      
        38
        32
         

      
        39
        33
         	for {