2020-08-07 12:47:20 +01:00
|
|
|
package router
|
2020-07-01 17:06:59 +01:00
|
|
|
|
|
|
|
import (
|
2021-01-29 13:17:32 +03:00
|
|
|
"github.com/unistack-org/micro/v3/register"
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/router"
|
2020-07-01 17:06:59 +01:00
|
|
|
)
|
|
|
|
|
2020-08-07 12:47:20 +01:00
|
|
|
type apiRouter struct {
|
|
|
|
router.Router
|
2021-03-06 19:45:13 +03:00
|
|
|
routes []router.Route
|
2020-08-07 12:47:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *apiRouter) Lookup(...router.QueryOption) ([]router.Route, error) {
|
|
|
|
return r.routes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *apiRouter) String() string {
|
|
|
|
return "api"
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// New router is a hack for API routing
|
2021-01-29 13:17:32 +03:00
|
|
|
func New(srvs []*register.Service) router.Router {
|
2020-07-01 17:06:59 +01: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}
|
|
|
|
}
|