micro/proxy/router/mucp/options.go

33 lines
671 B
Go
Raw Normal View History

2019-06-03 18:44:43 +01:00
package mucp
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 {
r = DefaultRouter
o.Server.Init(server.WithRouter(r))
}
// check its a proxy router
if proxyRouter, ok := r.(*Router); ok {
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))
}
}