Skip to content

Commit 80f0432

Browse files
author
myxy99
committed
xreminder
1 parent 5588b83 commit 80f0432

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

xreminder/xreminder.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ import (
88
"github.com/robfig/cron/v3"
99
)
1010

11-
type options struct {
12-
Spec []string `json:"spec,omitempty" yaml:"spec"`
11+
type config struct {
12+
Spec []string
1313
}
1414

15-
func NewReminderOptions() *options {
16-
return &options{
17-
Spec: []string{"* * * * * *"},
15+
type OptionFunc func(o *config)
16+
17+
func SetSpec(s []string) OptionFunc {
18+
return func(o *config) {
19+
o.Spec = s
20+
}
21+
}
22+
23+
func NewReminderCfg(of ...OptionFunc) *config {
24+
o := new(config)
25+
for _, optionFunc := range of {
26+
optionFunc(o)
1827
}
28+
return o
1929
}
2030

2131
type cronServer struct {
22-
o *options
32+
o *config
2333
c *cron.Cron
2434
}
2535

@@ -32,6 +42,6 @@ func (r *cronServer) Run(stopCh <-chan struct{}, f cron.Job) {
3242
r.c.Stop()
3343
}
3444

35-
func NewReminderClient(o *options) *cronServer {
45+
func NewReminderClient(o *config) *cronServer {
3646
return &cronServer{c: cron.New(), o: o}
3747
}

0 commit comments

Comments
 (0)