gitee.com/sasukebo/go-micro/v4@v4.7.1/api/handler/options.go (about) 1 package handler 2 3 import ( 4 "gitee.com/sasukebo/go-micro/v4/api/router" 5 "gitee.com/sasukebo/go-micro/v4/client" 6 ) 7 8 var ( 9 DefaultMaxRecvSize int64 = 1024 * 1024 * 100 // 10Mb 10 ) 11 12 type Options struct { 13 MaxRecvSize int64 14 Namespace string 15 Router router.Router 16 Client client.Client 17 } 18 19 type Option func(o *Options) 20 21 // NewOptions fills in the blanks 22 func NewOptions(opts ...Option) Options { 23 var options Options 24 for _, o := range opts { 25 o(&options) 26 } 27 28 if options.Client == nil { 29 WithClient(client.NewClient())(&options) 30 } 31 32 // set namespace if blank 33 if len(options.Namespace) == 0 { 34 WithNamespace("go.micro.api")(&options) 35 } 36 37 if options.MaxRecvSize == 0 { 38 options.MaxRecvSize = DefaultMaxRecvSize 39 } 40 41 return options 42 } 43 44 // WithNamespace specifies the namespace for the handler 45 func WithNamespace(s string) Option { 46 return func(o *Options) { 47 o.Namespace = s 48 } 49 } 50 51 // WithRouter specifies a router to be used by the handler 52 func WithRouter(r router.Router) Option { 53 return func(o *Options) { 54 o.Router = r 55 } 56 } 57 58 func WithClient(c client.Client) Option { 59 return func(o *Options) { 60 o.Client = c 61 } 62 } 63 64 // WithmaxRecvSize specifies max body size 65 func WithMaxRecvSize(size int64) Option { 66 return func(o *Options) { 67 o.MaxRecvSize = size 68 } 69 }