A Gin middleware for RPC-Style coding
- High Performance Use generics instead of reflection
- Simple to use
- Automatic parameter binding
- Unified response/error handling
$ go get github.com/apicat/ginrpc
type In struct {
ID int64 `uri:"id" binding:"required"`
}
type Out struct {
Message string `json:"message"`
}
func rpcHandleDemo(c *gin.Context, in *In) (*Out, error) {
return &Out{
Message: fmt.Sprintf(" myid = %d", in.ID),
}, nil
}
func main() {
e := gin.Default()
e.POST("/example/:id", ginrpc.Handle(rpcHandleDemo))
}
Inject custom configuration using middleware
ReponseRender
Customize the responseAutomaticBinding
Automatic binding default:enableRequestBeforeHook
Add a front hook With Handle
e := gin.Default()
e.Use(ginrpc.AutomaticBinding(false), ginrpc.RequestBeforeHook(customBind))