Skip to content

Commit

Permalink
handler: Move input check nearer its kinfolk.
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Sep 23, 2021
1 parent 1d7c832 commit 69a19b0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func Check(fn interface{}) (*FuncInfo, error) {
// Check argument values.
if np := info.Type.NumIn(); np == 0 || np > 2 {
return nil, errors.New("wrong number of parameters")
} else if info.Type.In(0) != ctxType {
return nil, errors.New("first parameter is not context.Context")
} else if np == 2 {
info.Argument = info.Type.In(1)
info.IsVariadic = info.Type.IsVariadic()
Expand All @@ -272,8 +274,6 @@ func Check(fn interface{}) (*FuncInfo, error) {
no := info.Type.NumOut()
if no < 1 || no > 2 {
return nil, errors.New("wrong number of results")
} else if info.Type.In(0) != ctxType {
return nil, errors.New("first parameter is not context.Context")
} else if no == 2 && info.Type.Out(1) != errType {
return nil, errors.New("result is not of type error")
}
Expand Down

0 comments on commit 69a19b0

Please sign in to comment.