Refrase README

Signed-off-by: René Jochum <rene@jochum.dev>
master
René Jochum 2 years ago
parent 69dd203d2a
commit db4a15594d

@ -1,9 +1,9 @@
# go-micro-router
# router
A dynamic router (API Gatway) for go-micro.
It looks for services that host "proto/routerclientpb/routerclientpb.RouterClient" and ask's them for services,
then it registers that service via a proxy method with gin.
It looks for services that host "proto/routerclientpb/routerclientpb.RouterClient" and ask's them for routes/endpoints,
then it registers that endpoints via a proxy method with gin.
## Caveats

@ -1,39 +0,0 @@
package client
import (
"context"
"github.com/go-micro/router/proto/routerclientpb"
"github.com/go-micro/router/util"
"google.golang.org/protobuf/types/known/emptypb"
)
// Handler is the handler for github.com/go-micro/router/proto/routerpb.RrouterService
type Handler struct {
routerURI string
routes []*routerclientpb.RoutesReply_Route
}
// NewHandler returns a new dynrouterpb Handler
func NewHandler(routerURI string, routes ...Route) *Handler {
pbRoutes := []*routerclientpb.RoutesReply_Route{}
for _, r := range routes {
pbRoutes = append(pbRoutes, &routerclientpb.RoutesReply_Route{
IsGlobal: r.IsGlobal,
Method: r.Method,
Path: r.Path,
Endpoint: util.ReflectFunctionName(r.Endpoint),
Params: r.Params,
})
}
return &Handler{routerURI, pbRoutes}
}
// Routes returns the registered routes
func (h *Handler) Routes(ctx context.Context, req *emptypb.Empty, rsp *routerclientpb.RoutesReply) error {
rsp.RouterURI = h.routerURI
rsp.Routes = h.routes
return nil
}

@ -1,60 +0,0 @@
package client
import "net/http"
type Route struct {
// isGlobal=True == no prefix route
IsGlobal bool
Method string
Path string
Endpoint interface{}
Params []string
}
type RouteOption func(*Route)
func NewRoute(endpoint interface{}, opts ...RouteOption) Route {
route := Route{
IsGlobal: false,
Method: http.MethodGet,
Path: "/",
Endpoint: endpoint,
Params: []string{},
}
for _, o := range opts {
o(&route)
}
return route
}
func RouteIsGlobal(n bool) RouteOption {
return func(o *Route) {
o.IsGlobal = n
}
}
func RouteMethod(n string) RouteOption {
return func(o *Route) {
o.Method = n
}
}
func RoutePath(n string) RouteOption {
return func(o *Route) {
o.Path = n
}
}
func RouteEndpoint(n interface{}) RouteOption {
return func(o *Route) {
o.Endpoint = n
}
}
func RouteParams(n []string) RouteOption {
return func(o *Route) {
o.Params = n
}
}
Loading…
Cancel
Save