2019-06-03 20:44:43 +03:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro"
|
|
|
|
"github.com/micro/go-micro/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WithBackend provides an option to set the proxy backend url
|
|
|
|
func WithBackend(url string) micro.Option {
|
|
|
|
return func(o *micro.Options) {
|
|
|
|
// get the router
|
|
|
|
r := o.Server.Options().Router
|
|
|
|
|
|
|
|
// not set
|
|
|
|
if r == nil {
|
2019-06-06 19:58:21 +03:00
|
|
|
r = DefaultProxy
|
2019-06-03 20:44:43 +03:00
|
|
|
o.Server.Init(server.WithRouter(r))
|
|
|
|
}
|
|
|
|
|
|
|
|
// check its a proxy router
|
2019-06-06 19:58:21 +03:00
|
|
|
if proxyRouter, ok := r.(*Proxy); ok {
|
2019-06-03 20:44:43 +03:00
|
|
|
proxyRouter.Backend = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRouter provides an option to set the proxy router
|
|
|
|
func WithRouter(r server.Router) micro.Option {
|
|
|
|
return func(o *micro.Options) {
|
|
|
|
o.Server.Init(server.WithRouter(r))
|
|
|
|
}
|
|
|
|
}
|