micro/api/handler/util/router.go
ben-toogood 174e44b846
Deprecate client/selector (#1767)
* client/{grpc,rpc}: depricate selector (wip)

* {client,cmd}: remove client/selector

* deprecate client/selector

* router/static: fix lookup

* config/cmd: add support for legacy static selector flag

* config/cmd: add support for legacy dns selector flag
2020-07-01 17:06:59 +01:00

33 lines
633 B
Go

package util
import (
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/router"
)
// Router is a hack for API routing
func Router(srvs []*registry.Service) router.Router {
var routes []router.Route
for _, srv := range srvs {
for _, n := range srv.Nodes {
routes = append(routes, router.Route{Address: n.Address, Metadata: n.Metadata})
}
}
return &apiRouter{routes: routes}
}
func (r *apiRouter) Lookup(...router.QueryOption) ([]router.Route, error) {
return r.routes, nil
}
type apiRouter struct {
routes []router.Route
router.Router
}
func (r *apiRouter) String() string {
return "api"
}