Skip to content

Commit

Permalink
refactor(config): rename StartStrategyType to InitStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Dec 6, 2023
1 parent 7a3c054 commit a6654dc
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 159 deletions.
18 changes: 9 additions & 9 deletions config/blocking.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ type Blocking struct {

// Deprecated options
Deprecated struct {
DownloadTimeout *Duration `yaml:"downloadTimeout"`
DownloadAttempts *uint `yaml:"downloadAttempts"`
DownloadCooldown *Duration `yaml:"downloadCooldown"`
RefreshPeriod *Duration `yaml:"refreshPeriod"`
FailStartOnListError *bool `yaml:"failStartOnListError"`
ProcessingConcurrency *uint `yaml:"processingConcurrency"`
StartStrategy *StartStrategyType `yaml:"startStrategy"`
MaxErrorsPerFile *int `yaml:"maxErrorsPerFile"`
DownloadTimeout *Duration `yaml:"downloadTimeout"`
DownloadAttempts *uint `yaml:"downloadAttempts"`
DownloadCooldown *Duration `yaml:"downloadCooldown"`
RefreshPeriod *Duration `yaml:"refreshPeriod"`
FailStartOnListError *bool `yaml:"failStartOnListError"`
ProcessingConcurrency *uint `yaml:"processingConcurrency"`
StartStrategy *InitStrategy `yaml:"startStrategy"`
MaxErrorsPerFile *int `yaml:"maxErrorsPerFile"`
} `yaml:",inline"`
}

Expand All @@ -36,7 +36,7 @@ func (c *Blocking) migrate(logger *logrus.Entry) bool {
"refreshPeriod": Move(To("loading.refreshPeriod", &c.Loading)),
"failStartOnListError": Apply(To("loading.strategy", &c.Loading.Init), func(oldValue bool) {
if oldValue {
c.Loading.Strategy = StartStrategyTypeFailOnError
c.Loading.Strategy = InitStrategyFailOnError
}
}),
"processingConcurrency": Move(To("loading.concurrency", &c.Loading)),
Expand Down
16 changes: 8 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ func (v *TLSVersion) validate(logger *logrus.Entry) {
// )
type QueryLogType int16

// StartStrategyType upstart strategy ENUM(
// InitStrategy startup strategy ENUM(
// blocking // synchronously download blocking lists on startup
// failOnError // synchronously download blocking lists on startup and shutdown on error
// fast // asyncronously download blocking lists on startup
// )
type StartStrategyType uint16
type InitStrategy uint16

func (s StartStrategyType) Do(ctx context.Context, init func(context.Context) error, logErr func(error)) error {
func (s InitStrategy) Do(ctx context.Context, init func(context.Context) error, logErr func(error)) error {
init = recoverToError(init, func(panicVal any) error {
return fmt.Errorf("panic during initialization: %v", panicVal)
})

if s == StartStrategyTypeFast {
if s == InitStrategyFast {
go func() {
err := init(ctx)
if err != nil {
Expand All @@ -136,7 +136,7 @@ func (s StartStrategyType) Do(ctx context.Context, init func(context.Context) er
if err != nil {
logErr(err)

if s == StartStrategyTypeFailOnError {
if s == InitStrategyFailOnError {
return err
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (c *toEnable) LogConfig(logger *logrus.Entry) {
}

type Init struct {
Strategy StartStrategyType `yaml:"strategy" default:"blocking"`
Strategy InitStrategy `yaml:"strategy" default:"blocking"`
}

func (c *Init) LogConfig(logger *logrus.Entry) {
Expand Down Expand Up @@ -563,9 +563,9 @@ func (cfg *Config) migrate(logger *logrus.Entry) bool {
"dohUserAgent": Move(To("upstreams.userAgent", &cfg.Upstreams)),
"startVerifyUpstream": Apply(To("upstreams.init.strategy", &cfg.Upstreams.Init), func(value bool) {
if value {
cfg.Upstreams.Init.Strategy = StartStrategyTypeFailOnError
cfg.Upstreams.Init.Strategy = InitStrategyFailOnError
} else {
cfg.Upstreams.Init.Strategy = StartStrategyTypeFast
cfg.Upstreams.Init.Strategy = InitStrategyFast
}
}),
})
Expand Down
178 changes: 89 additions & 89 deletions config/config_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6654dc

Please sign in to comment.