Popularity
5.8
Growing
Activity
0.0
-
282
9
34
Programming language: Go
License: Apache License 2.0
Tags:
Web Frameworks
Ginrpc alternatives and similar packages
Based on the "Web Frameworks" category.
Alternatively, view Ginrpc alternatives based on common mentions on social networks and blogs.
-
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. -
Iris
The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio :rocket: -
go-kratos
Your ultimate Go microservices framework for the cloud-native era. -
Gorilla WebSocket
A fast, well-tested and widely used WebSocket implementation for Go. -
chi
lightweight, idiomatic and composable router for building Go HTTP services -
GoFrame
GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang. -
go-socket.io
socket.io library for golang, a realtime application framework. -
Hertz
Go HTTP framework with high-performance and strong-extensibility for building micro-services. -
Macaron
Package macaron is a high productive and modular web framework in Go. -
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. -
render
Go package for easily rendering JSON, XML, binary data, and HTML templates responses. -
pat
Sinatra style pattern muxer for Go’s net/http library, by the author of Sinatra. -
Atreugo
High performance and extensible micro web framework. Zero memory allocations in hot paths. -
tigertonic
A Go framework for building JSON web services inspired by Dropwizard -
Goji
Goji is a minimalistic and flexible HTTP request multiplexer for Go (golang) -
fasthttprouter
A high performance fasthttp request router that scales well -
Beego
beego is an open-source, high-performance web framework for the Go programming language. -
go-server-timing
Go (golang) library for creating and consuming HTTP Server-Timing headers -
Gearbox
Gearbox :gear: is a web framework written in Go with a focus on high performance -
golongpoll
golang long polling library. Makes web pub-sub easy via HTTP long-poll servers and clients :smiley: :coffee: :computer:
Learn any GitHub repo in 59 seconds
Onboard AI learns any GitHub repo in minutes and lets you chat with it to locate functionality, understand different parts, and generate new code. Use it for free at www.getonboard.dev.
Promo
getonboard.dev
Do you think we are missing an alternative of Ginrpc or a related project?
Popular Comparisons
README
[中文文档](README_cn.md)
Automatic parameter binding base on go-gin
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
)
Installing
- go mod:
go get -u github.com/xxjwxc/ginrpc@master
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>>](hhttps://github.com/gmsec/gmsec)
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
@Router - [-]
indicates ignore
#### 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
go // 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 }