Skip to content

Commit

Permalink
fix: fix grpc proxy wrapper modify binder (#1094)
Browse files Browse the repository at this point in the history
fix grpc proxy wrapper modify binder
  • Loading branch information
linthan committed May 17, 2024
1 parent 4e3f297 commit d967017
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pkg/server/xecho/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"net/http"
"reflect"
"strings"
"sync"

"github.com/codegangsta/inject"
"github.com/douyu/jupiter/pkg/util/xerror"
Expand Down Expand Up @@ -77,22 +76,19 @@ func ProtoJSON(c echo.Context, code int, i interface{}) error {
return err
}

var grpcBinder = &ProtoBinder{}

// GRPCProxyWrapper ...
func GRPCProxyWrapper(h interface{}) echo.HandlerFunc {
t := reflect.TypeOf(h)
if t.Kind() != reflect.Func {
panic("reflect error: handler must be func")
}

once := sync.Once{}

return func(c echo.Context) error {
once.Do(func() {
c.Echo().Binder = &ProtoBinder{}
})

var req = reflect.New(t.In(1).Elem()).Interface()
if err := c.Bind(req); err != nil {
if err := grpcBinder.Bind(req, c); err != nil {
return ProtoError(c, http.StatusBadRequest, errBadRequest)
}

Expand Down

0 comments on commit d967017

Please sign in to comment.