Categorygithub.com/apicat/ginrpc
modulepackage
0.0.4
Repository: https://github.com/apicat/ginrpc.git
Documentation: pkg.go.dev

# README

ginrpc

中文

A Gin middleware for RPC-Style coding

  • High Performance Use generics instead of reflection
  • Simple to use
  • Automatic parameter binding
  • Unified response/error handling

Installation

$ go get github.com/apicat/ginrpc

Usage

base

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))
}

custom

Inject custom configuration using middleware

  • ReponseRender Customize the response
  • AutomaticBinding Automatic binding default:enable
  • RequestBeforeHook Add a front hook With Handle

See the full example

e := gin.Default()
e.Use(ginrpc.AutomaticBinding(false), ginrpc.RequestBeforeHook(customBind))

# Packages

No description provided by the author

# Functions

AutomaticBinding enable/disable automatic binding and parameter validation.
Handle for turning handlers into gin.handlefunc.
No description provided by the author
No description provided by the author
ReponseRender custom response output.
// RequestBeforeHook The input parameter error represents a binding verification error.

# Structs

Empty like google.protobuf.Empty.
Error is a response error with http status code and attributes.