micro/util/router/router.go
Vasiliy Tolstov 06136312bb
regen files with never protoc (#6)
* regen files with never protoc
* rewrite import path

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-08-19 17:47:17 +03:00

33 lines
640 B
Go

package router
import (
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/router"
)
type apiRouter struct {
routes []router.Route
router.Router
}
func (r *apiRouter) Lookup(...router.QueryOption) ([]router.Route, error) {
return r.routes, nil
}
func (r *apiRouter) String() string {
return "api"
}
// Router is a hack for API routing
func New(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}
}