github.com/xmidt-org/webpa-common@v1.11.9/service/consul/options.go (about) 1 package consul 2 3 import ( 4 "time" 5 6 "github.com/hashicorp/consul/api" 7 "github.com/xmidt-org/argus/chrysom" 8 ) 9 10 const DefaultDatacenterRetries = 10 11 12 type Watch struct { 13 Service string `json:"service,omitempty"` 14 Tags []string `json:"tags,omitempty"` 15 PassingOnly bool `json:"passingOnly"` 16 CrossDatacenter bool `json:"crossDatacenter"` 17 QueryOptions api.QueryOptions `json:"queryOptions"` 18 } 19 20 type Options struct { 21 Client *api.Config `json:"client"` 22 Chrysom chrysom.ClientConfig `json:"chrysom"` 23 DisableGenerateID bool `json:"disableGenerateID"` 24 DatacenterRetries int `json:"datacenterRetries"` 25 DatacenterWatchInterval time.Duration `json:"datacenterWatchInterval"` 26 Registrations []api.AgentServiceRegistration `json:"registrations,omitempty"` 27 Watches []Watch `json:"watches,omitempty"` 28 } 29 30 func (o *Options) config() *api.Config { 31 if o != nil && o.Client != nil { 32 return o.Client 33 } 34 35 return api.DefaultConfig() 36 } 37 38 func (o *Options) disableGenerateID() bool { 39 if o != nil { 40 return o.DisableGenerateID 41 } 42 43 return false 44 } 45 46 func (o *Options) datacenterRetries() int { 47 if o != nil && o.DatacenterRetries > 0 { 48 return o.DatacenterRetries 49 } 50 51 return DefaultDatacenterRetries 52 } 53 54 func (o *Options) registrations() []api.AgentServiceRegistration { 55 if o != nil && len(o.Registrations) > 0 { 56 return o.Registrations 57 } 58 59 return nil 60 } 61 62 func (o *Options) watches() []Watch { 63 if o != nil && len(o.Watches) > 0 { 64 return o.Watches 65 } 66 67 return nil 68 }