{"id":13786704,"url":"https://github.com/xxjwxc/ginrpc","last_synced_at":"2025-05-16T08:07:04.479Z","repository":{"id":57484704,"uuid":"193229346","full_name":"xxjwxc/ginrpc","owner":"xxjwxc","description":"gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具","archived":false,"fork":false,"pushed_at":"2025-03-13T04:50:02.000Z","size":28637,"stargazers_count":295,"open_issues_count":13,"forks_count":37,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T03:13:30.945Z","etag":null,"topics":["auto","bind","binding","gin","go","golang","grpc","grpc-go","markdown","middleware","mindoc","rpc","swagger"],"latest_commit_sha":null,"homepage":"https://xxjwxc.github.io/post/ginrpc/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xxjwxc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-22T12:03:53.000Z","updated_at":"2025-04-01T07:12:37.000Z","dependencies_parsed_at":"2024-10-14T00:22:21.809Z","dependency_job_id":"636a6f3b-d7a9-4660-b712-55a7a174edf9","html_url":"https://github.com/xxjwxc/ginrpc","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.3448275862068966,"last_synced_commit":"f637665659cabcda460cb1bdb5b17448a7a72d50"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxjwxc%2Fginrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxjwxc%2Fginrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxjwxc%2Fginrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxjwxc%2Fginrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xxjwxc","download_url":"https://codeload.github.com/xxjwxc/ginrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493385,"owners_count":22080127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto","bind","binding","gin","go","golang","grpc","grpc-go","markdown","middleware","mindoc","rpc","swagger"],"created_at":"2024-08-03T19:01:29.527Z","updated_at":"2025-05-16T08:06:59.453Z","avatar_url":"https://github.com/xxjwxc.png","language":"Go","funding_links":[],"categories":["Web Frameworks","Utility","Go","Web框架","web框架","web框架`web 框架`"],"sub_categories":["Fail injection","Utility/Miscellaneous","HTTP Clients","实用程序/Miscellaneous","版本控制","版本控制`版本控制相关库`"],"readme":"[![Build Status](https://travis-ci.org/xxjwxc/ginrpc.svg?branch=master)](https://travis-ci.org/xxjwxc/ginrpc)\n[![Go Report Card](https://goreportcard.com/badge/github.com/xxjwxc/ginrpc)](https://goreportcard.com/report/github.com/xxjwxc/ginrpc)\n[![codecov](https://codecov.io/gh/xxjwxc/ginrpc/branch/master/graph/badge.svg)](https://codecov.io/gh/xxjwxc/ginrpc)\n[![GoDoc](https://godoc.org/github.com/xxjwxc/ginrpc?status.svg)](https://godoc.org/github.com/xxjwxc/ginrpc)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) \n\u003ca href=\"https://hellogithub.com/repository/fbc519fa5a2e4e248eabd860a6f404ff\" target=\"_blank\"\u003e\u003cimg src=\"https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=fbc519fa5a2e4e248eabd860a6f404ff\u0026claim_uid=6IkmGoxiuN4LWFn\u0026theme=small\" alt=\"Featured｜HelloGitHub\" /\u003e\u003c/a\u003e\n\n# [中文文档](README_cn.md)\n\n## Automatic parameter binding base on [go-gin](https://github.com/gin-gonic/gin)\n\n![img](/image/ginrpc.gif)\n\n## doc \n\n![doc](/image/ginrpc_doc.gif)\n\n\n## Golang gin automatic parameter binding\n\n- Support for RPC automatic mapping\n- Support object registration\n- Support annotation routing\n- base on [go-gin](https://github.com/gin-gonic/gin) on json restful style\n- implementation of parameter filtering and binding with request\n- code registration simple and supports multiple ways of registration\n- [grpc-go](https://github.com/grpc/grpc-go) bind support\n- Support [swagger](http://editor.swagger.io/) [MORE](https://github.com/xxjwxc/gmsec)\n- Support [markdown/mindoc](https://www.iminho.me/) [MORE](https://github.com/xxjwxc/gmsec)\n- Support call before and after deal(`ginrpc.WithBeforeAfter`)\n\n- [DEMO](https://github.com/xxjwxc/gmsec)\n\n## Installing\n- go mod:\n```\ngo get -u github.com/xxjwxc/ginrpc@master\n```\n\n## API details\n\n### Three interface modes are supported\n\n- func(*gin.Context) // go-gin Raw interface\n\n  func(*api.Context) // Custom context type\n\n- func(*api.Context,req) // Custom context type,with request\n\n  func(*api.Context,*req)\n\n- func(*gin.Context,*req) // go-gin context,with request\n\n  func(*gin.Context,req)\n\n- func(*gin.Context,*req)(*resp,error) // go-gin context,with request,return parameter and error ==\u003e [grpc-go](https://github.com/grpc/grpc-go)\n\n  func(*gin.Context,req)(resp,error)\n\n## 一. Parameter auto binding,Object registration (annotation routing)\n\n### Initialization project (this project is named after `gmsec`)\n\t``` go mod init gmsec ```\n\n### coding [more\u003e\u003e](hhttps://github.com/gmsec/gmsec)\n\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t_ \"gmsec/routers\" // Debug mode requires adding [mod] / routes to register annotation routes.debug模式需要添加[mod]/routers 注册注解路由\n\t\"github.com/xxjwxc/public/mydoc/myswagger\" // swagger 支持\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/xxjwxc/ginrpc\"\n\t\"github.com/xxjwxc/ginrpc/api\"\n)\n\ntype ReqTest struct {\n\tAccess_token string `json:\"access_token\"`\n\tUserName     string `json:\"user_name\" binding:\"required\"` // With verification mode\n\tPassword     string `json:\"password\"`\n}\n\n// Hello ...\ntype Hello struct {\n}\n\n// Hello Annotated route (bese on beego way)\n// @Router /block [post,get]\nfunc (s *Hello) Hello(c *api.Context, req *ReqTest) {\n\tfmt.Println(req)\n\tc.JSON(http.StatusOK, \"ok\")\n}\n\n// Hello2 Route without annotation (the parameter is 2 default post)\nfunc (s *Hello) Hello2(c *gin.Context, req ReqTest) {\n\tfmt.Println(req)\n\tc.JSON(http.StatusOK, \"ok\")\n}\n\n// [grpc-go](https://github.com/grpc/grpc-go)\n// with request,return parameter and error\n// TestFun6 Route without annotation (the parameter is 2 default post)\nfunc TestFun6(c *gin.Context, req ReqTest) (*ReqTest, error) {\n\tfmt.Println(req)\n\t//c.JSON(http.StatusOK, req)\n\treturn \u0026req, nil\n}\n\nfunc main() {\n\n\t// swagger\n\tmyswagger.SetHost(\"https://localhost:8080\")\n\tmyswagger.SetBasePath(\"gmsec\")\n\tmyswagger.SetSchemes(true, false)\n\t// -----end --\n\tbase := ginrpc.New()\n\trouter := gin.Default() // or router :=  gin.Default().Group(\"/xxjwxc\")\n\tbase.Register(router, new(Hello)) // object register like(go-micro)\n\trouter.POST(\"/test6\", base.HandlerFunc(TestFun6))                            // function register\n\tbase.RegisterHandlerFunc(router, []string{\"post\", \"get\"}, \"/test\", TestFun6) \n\trouter.Run(\":8080\")\n}\n   ```\n\n### - Annotation routing related instructions\n\n```\n\n// @Router /block [post,get]\n@Router tag  \n/block router \n[post,get] method \n\n ```\n\n - `@Router - [-]` indicates ignore\n\n #### 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)\n\n\n\n### 1. Annotation route will automatically create `[mod]/routes/gen_router.go` file, which needs to be added when calling:\n\n\t```\n\t_ \"[mod]/routers\" // Debug mode requires adding [mod] / routes to register annotation routes\n\n\t```\n\n\tBy 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)\n\n### 2. way of annotation route :\n\n\tmore to saying  [gmsec](https://github.com/gmsec/gmsec)\n\n### 3. Parameter description\n\n\tginrpc.WithCtx ： Set custom context\n\n\tginrpc.WithDebug(true) : Set debug mode\n\t\n\tginrpc.WithOutDoc(true) : output markdown/swagger api doc\n\n\tginrpc.WithBigCamel(true) : Set big camel standard (false is web mode, _, lowercase)\n\n\tginrpc.WithBeforeAfter(\u0026ginrpc.DefaultGinBeforeAfter{}) : Before After call\n\n\t[more\u003e\u003e](https://godoc.org/github.com/xxjwxc/ginrpc)\n\n### 4. Execute curl to automatically bind parameters. See the results directly\n\n  ```\n  curl 'http://127.0.0.1:8080/xxjwxc/block' -H 'Content-Type: application/json' -d '{\"access_token\":\"111\", \"user_name\":\"222\", \"password\":\"333\"}'\n  ```\n\n  ```\n  curl 'http://127.0.0.1:8080/xxjwxc/hello.hello2' -H 'Content-Type: application/json' -d '{\"access_token\":\"111\", \"user_name\":\"222\", \"password\":\"333\"}'\n  ```\n\n## 二. swagger/markdown/mindoc Document generation description\n\n```\n\tginrpc.WithOutDoc(true) : output markdown/swagger\n```\n\n### 1.For object registration 'ginrpc. Register' mode, document export is supported\n### 2.Export supports annotation routing, Parameter annotation and default value (` tag '. ` default')\n### 3.Default export path:(`/docs/swagger/swagger.json`,`/docs/markdown`)\n### 4 struct demo\n```\ntype ReqTest struct {\n\tAccessToken string `json:\"access_token\"`\n\tUserName    string `json:\"user_name\" binding:\"required\"` // 带校验方式\n\tPassword    string `json:\"password\"`\n}\n```\n- [more \u003e\u003e\u003e](https://github.com/xxjwxc/gmsec)\n\n## 三. Support to call Middleware\n- using `ginrpc.WithBeforeAfter(\u0026ginrpc.DefaultGinBeforeAfter{})` \n- You can also implement functions (single types) on objects\n```go\n\t// GinBeforeAfter Execute middleware before and after the object call (support adding the object separately from the object in total)\n\ttype GinBeforeAfter interface {\n\t\tGinBefore(req *GinBeforeAfterInfo) bool\n\t\tGinAfter(req *GinBeforeAfterInfo) bool\n\t}\n```\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/xxjwxc/ginrpc.svg)](https://starchart.cc/xxjwxc/ginrpc)\n\n\n### coding address:[ginprc](https://github.com/xxjwxc/ginrpc) Please give star support","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxjwxc%2Fginrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxxjwxc%2Fginrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxjwxc%2Fginrpc/lists"}