2019-12-16 17:55:47 +03:00
|
|
|
// Package proxy is a transparent proxy built on the go-micro/server
|
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/client"
|
|
|
|
"github.com/unistack-org/micro/v3/router"
|
2019-12-16 17:55:47 +03:00
|
|
|
)
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Options for proxy
|
2019-12-16 17:55:47 +03:00
|
|
|
type Options struct {
|
|
|
|
// Specific endpoint to always call
|
|
|
|
Endpoint string
|
|
|
|
// The default client to use
|
|
|
|
Client client.Client
|
|
|
|
// The default router to use
|
|
|
|
Router router.Router
|
|
|
|
// Extra links for different clients
|
|
|
|
Links map[string]client.Client
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Option func signature
|
2019-12-16 17:55:47 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// WithEndpoint sets a proxy endpoint
|
|
|
|
func WithEndpoint(e string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Endpoint = e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithClient sets the client
|
|
|
|
func WithClient(c client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Client = c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRouter specifies the router to use
|
|
|
|
func WithRouter(r router.Router) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Router = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLink sets a link for outbound requests
|
|
|
|
func WithLink(name string, c client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
if o.Links == nil {
|
|
|
|
o.Links = make(map[string]client.Client)
|
|
|
|
}
|
|
|
|
o.Links[name] = c
|
|
|
|
}
|
|
|
|
}
|