micro/util/router/router.go
Vasiliy Tolstov bbbcb22565 fieldalignment of all structs to save memory
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-06 19:45:13 +03:00

33 lines
644 B
Go

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