2019-06-06 11:50:25 +03:00
|
|
|
// Package proxy is a transparent proxy built on the go-micro/server
|
|
|
|
package proxy
|
|
|
|
|
2019-06-06 19:49:41 +03:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-06-07 15:42:39 +03:00
|
|
|
"github.com/micro/go-micro/client"
|
2019-06-12 14:45:42 +03:00
|
|
|
"github.com/micro/go-micro/config/options"
|
2019-06-26 18:12:57 +03:00
|
|
|
"github.com/micro/go-micro/network/router"
|
2019-06-06 19:49:41 +03:00
|
|
|
"github.com/micro/go-micro/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Proxy can be used as a proxy server for go-micro services
|
|
|
|
type Proxy interface {
|
2019-06-06 19:55:32 +03:00
|
|
|
options.Options
|
2019-06-07 15:42:39 +03:00
|
|
|
// ServeRequest honours the server.Router interface
|
2019-06-06 19:58:21 +03:00
|
|
|
ServeRequest(context.Context, server.Request, server.Response) error
|
2019-06-06 19:49:41 +03:00
|
|
|
}
|
2019-06-07 15:42:39 +03:00
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultEndpoint = "localhost:9090"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WithEndpoint sets a proxy endpoint
|
|
|
|
func WithEndpoint(e string) options.Option {
|
|
|
|
return options.WithValue("proxy.endpoint", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithClient sets the client
|
|
|
|
func WithClient(c client.Client) options.Option {
|
|
|
|
return options.WithValue("proxy.client", c)
|
|
|
|
}
|
2019-06-26 18:12:57 +03:00
|
|
|
|
|
|
|
// WithRouter specifies the router to use
|
|
|
|
func WithRouter(r router.Router) options.Option {
|
|
|
|
return options.WithValue("proxy.router", r)
|
|
|
|
}
|