-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor method validation to its own file
- Loading branch information
Showing
4 changed files
with
72 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package proxy | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/LLKennedy/httpgrpc/internal/methods" | ||
) | ||
|
||
func validateMethod(apiMethod reflect.Method, serverType reflect.Type) error { | ||
name := apiMethod.Name | ||
trueName, valid := methods.MatchAndStrip(name) | ||
if !valid { | ||
return fmt.Errorf("httpgrpc: %s does not begin with a valid HTTP method", name) | ||
} | ||
serverMethod, found := serverType.MethodByName(trueName) | ||
if !found { | ||
return fmt.Errorf("httpgrpc: server is missing method %s", trueName) | ||
} | ||
expectedType := apiMethod.Type | ||
foundType := serverMethod.Type | ||
err := validateArgs(expectedType, foundType) | ||
if err != nil { | ||
return fmt.Errorf("httpgrpc: api/server arguments do not match for method (%s/%s): %v", name, trueName, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters