2020-08-07 14:47:20 +03:00
|
|
|
package router
|
2020-07-01 19:06:59 +03:00
|
|
|
|
|
|
|
import (
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/registry"
|
|
|
|
"github.com/micro/go-micro/v3/router"
|
2020-07-01 19:06:59 +03:00
|
|
|
)
|
|
|
|
|
2020-08-07 14:47:20 +03:00
|
|
|
type apiRouter struct {
|
|
|
|
routes []router.Route
|
|
|
|
router.Router
|
|
|
|
}
|
|
|
|
|
2020-08-21 11:23:01 +03:00
|
|
|
func (r *apiRouter) Lookup(service string, opts ...router.LookupOption) ([]router.Route, error) {
|
2020-08-07 14:47:20 +03:00
|
|
|
return r.routes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *apiRouter) String() string {
|
|
|
|
return "api"
|
|
|
|
}
|
|
|
|
|
2020-07-01 19:06:59 +03:00
|
|
|
// Router is a hack for API routing
|
2020-08-07 14:47:20 +03:00
|
|
|
func New(srvs []*registry.Service) router.Router {
|
2020-07-01 19:06:59 +03:00
|
|
|
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}
|
|
|
|
}
|