All Projects → xxjwxc → Ginrpc

xxjwxc / Ginrpc

Licence: gpl-3.0
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Ginrpc

Gin Swagger
gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
Stars: ✭ 2,001 (+1174.52%)
Mutual labels:  swagger, middleware, gin
Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-6.37%)
Mutual labels:  swagger, grpc, rpc
Magiconion
Unified Realtime/API framework for .NET platform and Unity.
Stars: ✭ 2,505 (+1495.54%)
Mutual labels:  swagger, grpc, rpc
Joynr
A transport protocol agnostic (MQTT, HTTP, WebSockets etc.) Franca IDL based communication framework supporting multiple communication paradigms (RPC, Pub-Sub, broadcast etc.)
Stars: ✭ 124 (-21.02%)
Mutual labels:  rpc, middleware
Faygo
Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.
Stars: ✭ 1,557 (+891.72%)
Mutual labels:  swagger, middleware
Purerpc
Asynchronous pure Python gRPC client and server implementation supporting asyncio, uvloop, curio and trio
Stars: ✭ 125 (-20.38%)
Mutual labels:  grpc, rpc
Ultimate Go
This repo contains my notes on working with Go and computer systems.
Stars: ✭ 1,530 (+874.52%)
Mutual labels:  grpc, gin
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+1136.31%)
Mutual labels:  middleware, swagger
Http Router
🎉 Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
Stars: ✭ 124 (-21.02%)
Mutual labels:  swagger, middleware
Go Grpc
A collection of gRPC and Go examples showcasing features of the framework
Stars: ✭ 127 (-19.11%)
Mutual labels:  grpc, rpc
Graphql Mesh
GraphQL Mesh — Query anything, run anywhere
Stars: ✭ 2,114 (+1246.5%)
Mutual labels:  swagger, grpc
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+1003.82%)
Mutual labels:  swagger, markdown
Rpc Framework Tutorials
Java分布式RPC服务框架教程,包括 Dubbo/Dubbox, Motan, gRPC.
Stars: ✭ 114 (-27.39%)
Mutual labels:  grpc, rpc
Gzip
💾 Golang gzip middleware for Gin and net/http | Golang gzip中间件,支持Gin和net/http,开箱即用同时可定制
Stars: ✭ 113 (-28.03%)
Mutual labels:  middleware, gin
Go Http Metrics
Go modular http middleware to measure HTTP requests independent of metrics backend (with Prometheus and OpenCensus as backend implementations) and http framework/library
Stars: ✭ 128 (-18.47%)
Mutual labels:  middleware, gin
Asgard
Asgarde Framework
Stars: ✭ 138 (-12.1%)
Mutual labels:  grpc, gin
Grpc Gateway
The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.
Stars: ✭ 12,223 (+7685.35%)
Mutual labels:  swagger, grpc
Gin
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Stars: ✭ 53,971 (+34276.43%)
Mutual labels:  middleware, gin
Gin Web
由gin + gorm + jwt + casbin组合实现的RBAC权限管理脚手架Golang版, 搭建完成即可快速、高效投入业务开发
Stars: ✭ 107 (-31.85%)
Mutual labels:  middleware, gin
Swagger Markdown
swagger to markdown translater
Stars: ✭ 127 (-19.11%)
Mutual labels:  swagger, markdown

Build Status Go Report Card codecov GoDoc Mentioned in Awesome Go

中文文档

Automatic parameter binding base on go-gin

img

doc

doc

Golang gin automatic parameter binding

  • Support for RPC automatic mapping

  • Support object registration

  • Support annotation routing

  • base on go-gin on json restful style

  • implementation of parameter filtering and binding with request

  • code registration simple and supports multiple ways of registration

  • grpc-go bind support

  • Support swagger MORE

  • Support markdown/mindoc MORE

  • Support call before and after deal(ginrpc.WithBeforeAfter)

  • DEMO

Installing

  • go mod:
go get -u github.com/xxjwxc/[email protected]

API details

Three interface modes are supported

  • func(*gin.Context) // go-gin Raw interface

    func(*api.Context) // Custom context type

  • func(*api.Context,req) // Custom context type,with request

    func(*api.Context,*req)

  • func(*gin.Context,*req) // go-gin context,with request

    func(*gin.Context,req)

  • func(*gin.Context,*req)(*resp,error) // go-gin context,with request,return parameter and error ==> grpc-go

    func(*gin.Context,req)(resp,error)

一. Parameter auto binding,Object registration (annotation routing)

Initialization project (this project is named after gmsec)

``` go mod init gmsec ```

coding more>>


package main

import (
	"fmt"
	"net/http"

	_ "gmsec/routers" // Debug mode requires adding [mod] / routes to register annotation routes.debug模式需要添加[mod]/routers 注册注解路由
	"github.com/xxjwxc/public/mydoc/myswagger" // swagger 支持

	"github.com/gin-gonic/gin"
	"github.com/xxjwxc/ginrpc"
	"github.com/xxjwxc/ginrpc/api"
)

type ReqTest struct {
	Access_token string `json:"access_token"`
	UserName     string `json:"user_name" binding:"required"` // With verification mode
	Password     string `json:"password"`
}

// Hello ...
type Hello struct {
}

// Hello Annotated route (bese on beego way)
// @Router /block [post,get]
func (s *Hello) Hello(c *api.Context, req *ReqTest) {
	fmt.Println(req)
	c.JSON(http.StatusOK, "ok")
}

// Hello2 Route without annotation (the parameter is 2 default post)
func (s *Hello) Hello2(c *gin.Context, req ReqTest) {
	fmt.Println(req)
	c.JSON(http.StatusOK, "ok")
}

// [grpc-go](https://github.com/grpc/grpc-go)
// with request,return parameter and error
// TestFun6 Route without annotation (the parameter is 2 default post)
func TestFun6(c *gin.Context, req ReqTest) (*ReqTest, error) {
	fmt.Println(req)
	//c.JSON(http.StatusOK, req)
	return &req, nil
}

func main() {

	// swagger
	myswagger.SetHost("https://localhost:8080")
	myswagger.SetBasePath("gmsec")
	myswagger.SetSchemes(true, false)
	// -----end --
	base := ginrpc.New()
	router := gin.Default() // or router :=  gin.Default().Group("/xxjwxc")
	base.Register(router, new(Hello)) // object register like(go-micro)
	router.POST("/test6", base.HandlerFunc(TestFun6))                            // function register
	base.RegisterHandlerFunc(router, []string{"post", "get"}, "/test", TestFun6) 
	router.Run(":8080")
}

- Annotation routing related instructions


// @Router /block [post,get]
@Router tag  
/block router 
[post,get] method 

Note: if there is no annotation route in the object function, the system will add annotation route by default. Post mode: with req (2 parameters (CTX, req)), get mode is a parameter (CTX)

1. Annotation route will automatically create [mod]/routes/gen_router.go file, which needs to be added when calling:

```
_ "[mod]/routers" // Debug mode requires adding [mod] / routes to register annotation routes

```

By default, the [gen_router. Data] file will also be generated in the root directory of the project (keep this file, and you can embed it without adding the above code)

2. way of annotation route :

more to saying  [gmsec](https://github.com/gmsec/gmsec)

3. Parameter description

ginrpc.WithCtx : Set custom context

ginrpc.WithDebug(true) : Set debug mode

ginrpc.WithOutDoc(true) : output markdown/swagger api doc

ginrpc.WithBigCamel(true) : Set big camel standard (false is web mode, _, lowercase)

ginrpc.WithBeforeAfter(&ginrpc.DefaultGinBeforeAfter{}) : Before After call

[more>>](https://godoc.org/github.com/xxjwxc/ginrpc)

4. Execute curl to automatically bind parameters. See the results directly

curl 'http://127.0.0.1:8080/xxjwxc/block' -H 'Content-Type: application/json' -d '{"access_token":"111", "user_name":"222", "password":"333"}'
curl 'http://127.0.0.1:8080/xxjwxc/hello.hello2' -H 'Content-Type: application/json' -d '{"access_token":"111", "user_name":"222", "password":"333"}'

二. swagger/markdown/mindoc Document generation description

	ginrpc.WithOutDoc(true) : output markdown/swagger

1.For object registration 'ginrpc. Register' mode, document export is supported

2.Export supports annotation routing, Parameter annotation and default value (tag '. default')

3.Default export path:(/docs/swagger/swagger.json,/docs/markdown)

4 struct demo

type ReqTest struct {
	AccessToken string `json:"access_token"`
	UserName    string `json:"user_name" binding:"required"` // 带校验方式
	Password    string `json:"password"`
}

三. Support to call Middleware

  • using ginrpc.WithBeforeAfter(&ginrpc.DefaultGinBeforeAfter{})
  • You can also implement functions (single types) on objects
	// GinBeforeAfter Execute middleware before and after the object call (support adding the object separately from the object in total)
	type GinBeforeAfter interface {
		GinBefore(req *GinBeforeAfterInfo) bool
		GinAfter(req *GinBeforeAfterInfo) bool
	}

Stargazers over time

Stargazers over time

coding address:ginprc Please give star support

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].