github.com/micro/go-micro/v2@v2.9.1/router/options.go (about) 1 package router 2 3 import ( 4 "github.com/google/uuid" 5 "github.com/micro/go-micro/v2/client" 6 "github.com/micro/go-micro/v2/registry" 7 ) 8 9 // Options are router options 10 type Options struct { 11 // Id is router id 12 Id string 13 // Address is router address 14 Address string 15 // Gateway is network gateway 16 Gateway string 17 // Network is network address 18 Network string 19 // Registry is the local registry 20 Registry registry.Registry 21 // Advertise is the advertising strategy 22 Advertise Strategy 23 // Client for calling router 24 Client client.Client 25 } 26 27 // Id sets Router Id 28 func Id(id string) Option { 29 return func(o *Options) { 30 o.Id = id 31 } 32 } 33 34 // Address sets router service address 35 func Address(a string) Option { 36 return func(o *Options) { 37 o.Address = a 38 } 39 } 40 41 // Client to call router service 42 func Client(c client.Client) Option { 43 return func(o *Options) { 44 o.Client = c 45 } 46 } 47 48 // Gateway sets network gateway 49 func Gateway(g string) Option { 50 return func(o *Options) { 51 o.Gateway = g 52 } 53 } 54 55 // Network sets router network 56 func Network(n string) Option { 57 return func(o *Options) { 58 o.Network = n 59 } 60 } 61 62 // Registry sets the local registry 63 func Registry(r registry.Registry) Option { 64 return func(o *Options) { 65 o.Registry = r 66 } 67 } 68 69 // Strategy sets route advertising strategy 70 func Advertise(a Strategy) Option { 71 return func(o *Options) { 72 o.Advertise = a 73 } 74 } 75 76 // DefaultOptions returns router default options 77 func DefaultOptions() Options { 78 return Options{ 79 Id: uuid.New().String(), 80 Address: DefaultAddress, 81 Network: DefaultNetwork, 82 Registry: registry.DefaultRegistry, 83 Advertise: AdvertiseLocal, 84 } 85 }