github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/api/router/options.go (about) 1 // Copyright 2020 Asim Aslam 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Original source: github.com/micro/go-micro/v3/api/router/options.go 16 17 package router 18 19 import ( 20 "github.com/tickoalcantara12/micro/v3/service/api/resolver" 21 "github.com/tickoalcantara12/micro/v3/service/api/resolver/vpath" 22 "github.com/tickoalcantara12/micro/v3/service/registry" 23 "github.com/tickoalcantara12/micro/v3/service/registry/memory" 24 ) 25 26 type Options struct { 27 Handler string 28 Registry registry.Registry 29 Resolver resolver.Resolver 30 } 31 32 type Option func(o *Options) 33 34 func NewOptions(opts ...Option) Options { 35 options := Options{ 36 Handler: "meta", 37 Registry: memory.NewRegistry(), 38 } 39 40 for _, o := range opts { 41 o(&options) 42 } 43 44 if options.Resolver == nil { 45 options.Resolver = vpath.NewResolver( 46 resolver.WithHandler(options.Handler), 47 ) 48 } 49 50 return options 51 } 52 53 func WithHandler(h string) Option { 54 return func(o *Options) { 55 o.Handler = h 56 } 57 } 58 59 func WithRegistry(r registry.Registry) Option { 60 return func(o *Options) { 61 o.Registry = r 62 } 63 } 64 65 func WithResolver(r resolver.Resolver) Option { 66 return func(o *Options) { 67 o.Resolver = r 68 } 69 }