Files
timerx/option.go
T

49 lines
748 B
Go
Raw Normal View History

2024-04-04 10:58:57 +08:00
package timerx
2024-05-30 11:02:44 +08:00
import "time"
2024-04-04 10:58:57 +08:00
type Options struct {
2024-06-22 15:34:49 +08:00
logger Logger
location *time.Location
timeout time.Duration
2024-04-04 10:58:57 +08:00
}
func defaultOptions() Options {
return Options{
2024-06-22 15:34:49 +08:00
logger: NewLogger(),
location: time.Local,
timeout: time.Hour,
2024-04-04 10:58:57 +08:00
}
}
type Option func(*Options)
func newOptions(opts ...Option) Options {
o := defaultOptions()
for _, opt := range opts {
opt(&o)
}
return o
}
2024-05-07 20:26:13 +08:00
// 设置日志
2024-04-04 10:58:57 +08:00
func SetLogger(log Logger) Option {
return func(o *Options) {
o.logger = log
}
}
2024-05-07 20:26:13 +08:00
// 设定时区
2024-05-30 11:02:44 +08:00
func SetTimeZone(zone *time.Location) Option {
2024-05-07 20:26:13 +08:00
return func(o *Options) {
2024-05-30 11:02:44 +08:00
o.location = zone
2024-05-07 20:26:13 +08:00
}
}
2024-06-22 15:34:49 +08:00
// 设置任务最长执行时间
func SetTimeout(d time.Duration) Option {
return func(o *Options) {
o.timeout = d
}
}