github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/proxy/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/proxy/options.go 16 17 // Package proxy is a transparent proxy built on the go-micro/server 18 package proxy 19 20 import ( 21 "github.com/tickoalcantara12/micro/v3/service/client" 22 "github.com/tickoalcantara12/micro/v3/service/router" 23 ) 24 25 type Options struct { 26 // Specific endpoint to always call 27 Endpoint string 28 // The default client to use 29 Client client.Client 30 // The default router to use 31 Router router.Router 32 // Extra links for different clients 33 Links map[string]client.Client 34 } 35 36 type Option func(o *Options) 37 38 // WithEndpoint sets a proxy endpoint 39 func WithEndpoint(e string) Option { 40 return func(o *Options) { 41 o.Endpoint = e 42 } 43 } 44 45 // WithClient sets the client 46 func WithClient(c client.Client) Option { 47 return func(o *Options) { 48 o.Client = c 49 } 50 } 51 52 // WithRouter specifies the router to use 53 func WithRouter(r router.Router) Option { 54 return func(o *Options) { 55 o.Router = r 56 } 57 } 58 59 // WithLink sets a link for outbound requests 60 func WithLink(name string, c client.Client) Option { 61 return func(o *Options) { 62 if o.Links == nil { 63 o.Links = make(map[string]client.Client) 64 } 65 o.Links[name] = c 66 } 67 }