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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 21 deletions

View File

@ -6,11 +6,11 @@ import (
goapi "github.com/micro/go-micro/v3/api" goapi "github.com/micro/go-micro/v3/api"
"github.com/micro/go-micro/v3/api/handler" "github.com/micro/go-micro/v3/api/handler"
"github.com/micro/go-micro/v3/api/handler/util"
api "github.com/micro/go-micro/v3/api/proto" api "github.com/micro/go-micro/v3/api/proto"
"github.com/micro/go-micro/v3/client" "github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/errors" "github.com/micro/go-micro/v3/errors"
"github.com/micro/go-micro/v3/util/ctx" "github.com/micro/go-micro/v3/util/ctx"
"github.com/micro/go-micro/v3/util/router"
) )
type apiHandler struct { type apiHandler struct {
@ -72,7 +72,7 @@ func (a *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// create the context from headers // create the context from headers
cx := ctx.FromRequest(r) cx := ctx.FromRequest(r)
if err := c.Call(cx, req, rsp, client.WithRouter(util.Router(service.Services))); err != nil { if err := c.Call(cx, req, rsp, client.WithRouter(router.New(service.Services))); err != nil {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
ce := errors.Parse(err.Error()) ce := errors.Parse(err.Error())
switch ce.Code { switch ce.Code {

View File

@ -11,7 +11,6 @@ import (
jsonpatch "github.com/evanphx/json-patch/v5" jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/micro/go-micro/v3/api" "github.com/micro/go-micro/v3/api"
"github.com/micro/go-micro/v3/api/handler" "github.com/micro/go-micro/v3/api/handler"
"github.com/micro/go-micro/v3/api/handler/util"
"github.com/micro/go-micro/v3/api/internal/proto" "github.com/micro/go-micro/v3/api/internal/proto"
"github.com/micro/go-micro/v3/client" "github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/codec" "github.com/micro/go-micro/v3/codec"
@ -22,6 +21,7 @@ import (
"github.com/micro/go-micro/v3/metadata" "github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/util/ctx" "github.com/micro/go-micro/v3/util/ctx"
"github.com/micro/go-micro/v3/util/qson" "github.com/micro/go-micro/v3/util/qson"
"github.com/micro/go-micro/v3/util/router"
"github.com/oxtoacart/bpool" "github.com/oxtoacart/bpool"
) )
@ -113,7 +113,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// create custom router // create custom router
callOpt := client.WithRouter(util.Router(service.Services)) callOpt := client.WithRouter(router.New(service.Services))
// walk the standard call path // walk the standard call path
// get payload // get payload

View File

@ -13,10 +13,10 @@ import (
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
"github.com/micro/go-micro/v3/api" "github.com/micro/go-micro/v3/api"
"github.com/micro/go-micro/v3/api/handler/util"
"github.com/micro/go-micro/v3/client" "github.com/micro/go-micro/v3/client"
raw "github.com/micro/go-micro/v3/codec/bytes" raw "github.com/micro/go-micro/v3/codec/bytes"
"github.com/micro/go-micro/v3/logger" "github.com/micro/go-micro/v3/logger"
"github.com/micro/go-micro/v3/util/router"
) )
// serveWebsocket will stream rpc back over websockets assuming json // serveWebsocket will stream rpc back over websockets assuming json
@ -111,7 +111,7 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
) )
// create custom router // create custom router
callOpt := client.WithRouter(util.Router(service.Services)) callOpt := client.WithRouter(router.New(service.Services))
// create a new stream // create a new stream
stream, err := c.Stream(ctx, req, callOpt) stream, err := c.Stream(ctx, req, callOpt)

View File

@ -1,12 +1,25 @@
package util package router
import ( import (
"github.com/micro/go-micro/v3/registry" "github.com/micro/go-micro/v3/registry"
"github.com/micro/go-micro/v3/router" "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 // Router is a hack for API routing
func Router(srvs []*registry.Service) router.Router { func New(srvs []*registry.Service) router.Router {
var routes []router.Route var routes []router.Route
for _, srv := range srvs { for _, srv := range srvs {
@ -17,16 +30,3 @@ func Router(srvs []*registry.Service) router.Router {
return &apiRouter{routes: routes} return &apiRouter{routes: routes}
} }
func (r *apiRouter) Lookup(...router.QueryOption) ([]router.Route, error) {
return r.routes, nil
}
type apiRouter struct {
routes []router.Route
router.Router
}
func (r *apiRouter) String() string {
return "api"
}