Skip to content

apicat/ginrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A Gin middleware for RPC-Style coding

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages