remove handler/util package in favour of util/router (#1908)

This commit is contained in:
Asim Aslam
2020-08-07 12:47:20 +01:00
committed by GitHub
parent 37cc7fda92
commit 8ee31b94a1
4 changed files with 21 additions and 21 deletions

32
util/router/router.go Normal file
View File

@@ -0,0 +1,32 @@
package router
import (
"github.com/micro/go-micro/v3/registry"
"github.com/micro/go-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}
}