Skip to content

Commit

Permalink
fix for grpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Apr 19, 2017
1 parent ff9b60a commit a91d52c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ func (m *Mounter) Handler(f interface{}) http.Handler {
numIn := ft.NumIn()
mapIn := make(map[mapIndex]int)
for i := 0; i < numIn; i++ {
switch ft.In(i).String() {
fi := ft.In(i)

// assume this is grpc call options
if fi.Kind() == reflect.Slice && i == numIn-1 {
numIn--
break
}

switch fi.String() {
case strContext:
setOrPanic(mapIn, miContext, i)
case strRequest:
Expand Down
9 changes: 9 additions & 0 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ func TestHandler(t *testing.T) {
reset()
h.ServeHTTP(w, r)
mustNothing()

// grpc style
h = m.Handler(func(ctx context.Context, req *requestType, opts ...interface{}) (interface{}, error) {
return map[string]string{"ok": "1"}, nil
})
r = httptest.NewRequest(http.MethodPost, "http://localhost", successBody)
reset()
h.ServeHTTP(w, r)
mustSuccess()
}

func TestDefault(t *testing.T) {
Expand Down

0 comments on commit a91d52c

Please sign in to comment.