1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/plugins/proxy/http/options.go
2021-10-12 12:55:53 +01:00

33 lines
646 B
Go

package http
import (
"go-micro.dev/v4"
"go-micro.dev/v4/server"
)
// WithBackend provides an option to set the http 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 http router
if httpRouter, ok := r.(*Router); ok {
httpRouter.Backend = url
}
}
}
// WithRouter provides an option to set the http router
func WithRouter(r server.Router) micro.Option {
return func(o *micro.Options) {
o.Server.Init(server.WithRouter(r))
}
}