gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/api/handler/options.go (about) 1 package handler 2 3 import ( 4 "gitee.com/liuxuezhan/go-micro-v1.18.0" 5 "gitee.com/liuxuezhan/go-micro-v1.18.0/api/router" 6 ) 7 8 type Options struct { 9 Namespace string 10 Router router.Router 11 Service micro.Service 12 } 13 14 type Option func(o *Options) 15 16 // NewOptions fills in the blanks 17 func NewOptions(opts ...Option) Options { 18 var options Options 19 for _, o := range opts { 20 o(&options) 21 } 22 23 // create service if its blank 24 if options.Service == nil { 25 WithService(micro.NewService())(&options) 26 } 27 28 // set namespace if blank 29 if len(options.Namespace) == 0 { 30 WithNamespace("go.micro.api")(&options) 31 } 32 33 return options 34 } 35 36 // WithNamespace specifies the namespace for the handler 37 func WithNamespace(s string) Option { 38 return func(o *Options) { 39 o.Namespace = s 40 } 41 } 42 43 // WithRouter specifies a router to be used by the handler 44 func WithRouter(r router.Router) Option { 45 return func(o *Options) { 46 o.Router = r 47 } 48 } 49 50 // WithService specifies a micro.Service 51 func WithService(s micro.Service) Option { 52 return func(o *Options) { 53 o.Service = s 54 } 55 }