github.com/songzhibin97/gkit@v1.2.13/distributed/schedule/option.go (about) 1 package schedule 2 3 import ( 4 "github.com/songzhibin97/gkit/options" 5 ) 6 7 type Interval int 8 9 const ( 10 Second Interval = 1 << iota // Seconds field, default 0 11 SecondOptional // Optional seconds field, default 0 12 Minute // Minutes field, default 0 13 Hour // Hours field, default 0 14 Dom // Day of month field, default * 15 Month // Month field, default * 16 Dow // Day of week field, default * 17 DowOptional // Optional day of week field, default * 18 Descriptor // Allow descriptors such as @monthly, @weekly, etc. 19 ) 20 21 var places = []Interval{ 22 Second, 23 Minute, 24 Hour, 25 Dom, 26 Month, 27 Dow, 28 } 29 30 var defaults = []string{ 31 "0", 32 "0", 33 "0", 34 "*", 35 "*", 36 "*", 37 } 38 39 type Config struct { 40 interval Interval 41 } 42 43 func WithInterval(options Interval) options.Option { 44 return func(o interface{}) { 45 optionals := 0 46 if options&DowOptional > 0 { 47 optionals++ 48 } 49 if options&SecondOptional > 0 { 50 optionals++ 51 } 52 if optionals > 1 { 53 panic("multiple optionals may not be configured") 54 } 55 o.(*Config).interval = options 56 } 57 }