uniugm/admin/lib/node/app_options.go
2025-04-18 17:17:23 +08:00

32 lines
803 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package node
// WithAppBootFlag 设置app的起服参数flags必须为结构体指针
// 只支持string/int/int64/bool四种字段类型例如
//
// type Flags struct {
// F1 string `env:"id" desc:"boot id" default:"default value"`
// F2 int `env:"num" desc:"number" default:"3"`
// }
// WithAppBootFlag(&Flags{})
func WithAppBootFlag(flag interface{}) AppOption {
return appOptionFunction(func(app *Application) {
app.bootFlag = flag
})
}
func WithAppStopTask(desc string, task Task) AppOption {
return appOptionFunction(func(app *Application) {
app.stopTasks = append(app.stopTasks, pair{desc, task})
})
}
type AppOption interface {
Apply(scd *Application)
}
type appOptionFunction func(app *Application)
func (of appOptionFunction) Apply(app *Application) {
of(app)
}