diff options
Diffstat (limited to 'service_options.go')
| -rw-r--r-- | service_options.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/service_options.go b/service_options.go index 957987a..fc0da11 100644 --- a/service_options.go +++ b/service_options.go @@ -5,6 +5,7 @@ package lilin import ( "fmt" + "log" "net" "net/http" "net/url" @@ -19,6 +20,9 @@ const ( serviceKindUDP = `udp` ) +// defInterval define default interval in between scanning run. +const defInterval = 1 * time.Minute + type ServiceOptions struct { scanURL *url.URL @@ -37,7 +41,12 @@ type ServiceOptions struct { // Timeout for connecting and reading response from service. Timeout string `ini:"::timeout"` - timeout time.Duration + // Interval between each scan. + // The minimum value is 60 seconds or 1 minute. + Interval string `ini:"::interval"` + + timeout time.Duration + interval time.Duration } func (opts *ServiceOptions) init() (err error) { @@ -85,5 +94,19 @@ func (opts *ServiceOptions) init() (err error) { return fmt.Errorf(`invalid Timeout %s`, opts.Timeout) } } + + if len(opts.Interval) == 0 { + opts.interval = defInterval + } else { + opts.interval, err = time.ParseDuration(opts.Interval) + if err != nil { + return fmt.Errorf(`invalid Interval %s`, opts.Interval) + } + if opts.interval < defInterval { + log.Printf(`%s: interval is less than %s, revert to default`, + opts.Name, defInterval) + opts.interval = defInterval + } + } return nil } |
