{"id":20706002,"url":"https://github.com/gmsec/gmsec","last_synced_at":"2025-03-17T14:12:20.286Z","repository":{"id":38223704,"uuid":"245175257","full_name":"gmsec/gmsec","owner":"gmsec","description":"golang micro service base on gin. golang 微服务集成框架","archived":false,"fork":false,"pushed_at":"2024-07-26T08:43:56.000Z","size":67305,"stargazers_count":181,"open_issues_count":3,"forks_count":27,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-25T16:49:53.133Z","etag":null,"topics":["gin","gmsec","go-micro","golang","grpc","microservice","swagger"],"latest_commit_sha":null,"homepage":"","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/gmsec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["xxjwxc"],"custom":["https://www.paypal.me/xxjwxc"],"patreon":"xxjwxc"}},"created_at":"2020-03-05T13:49:34.000Z","updated_at":"2025-01-06T08:56:39.000Z","dependencies_parsed_at":"2024-11-15T22:26:39.196Z","dependency_job_id":"aeb871b4-a95b-4894-81ed-c91ad97c5999","html_url":"https://github.com/gmsec/gmsec","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmsec%2Fgmsec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmsec%2Fgmsec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmsec%2Fgmsec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmsec%2Fgmsec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmsec","download_url":"https://codeload.github.com/gmsec/gmsec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241960880,"owners_count":20049343,"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":["gin","gmsec","go-micro","golang","grpc","microservice","swagger"],"created_at":"2024-11-17T01:20:56.756Z","updated_at":"2025-03-05T04:14:29.433Z","avatar_url":"https://github.com/gmsec.png","language":"Go","funding_links":["https://github.com/sponsors/xxjwxc","https://www.paypal.me/xxjwxc","https://patreon.com/xxjwxc"],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/gmsec/gmsec.svg?branch=master)](https://travis-ci.org/gmsec/gmsec)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gmsec/gmsec)](https://goreportcard.com/report/github.com/gmsec/gmsec)\n[![codecov](https://codecov.io/gh/gmsec/gmsec/branch/master/graph/badge.svg)](https://codecov.io/gh/gmsec/gmsec)\n[![GoDoc](https://godoc.org/github.com/gmsec/gmsec?status.svg)](https://godoc.org/github.com/gmsec/gmsec)\n\n\n# [gmsec](https://github.com/gmsec/gmsec)\n\n### 特点\n\n- 打通grpc + gin，同时支持grpc 跟 restful 模式\n- grpc , gin 公用端口\n- gorm 嵌入，自动数据库代码生成\n\n### golang 微服务集成框架 \n\n- [grpc](https://github.com/grpc/grpc-go)\n- [gorm 自动构建(gormt)](https://github.com/xxjwxc/gormt)\n- [gin 参数自动绑定(ginrpc)](https://github.com/xxjwxc/ginrpc)\n- [dns 注册发现(mdns)](https://github.com/asim/mdns)\n- [markdown/mindoc 文档自动导出](https://github.com/grpc)\n- [支持etcd/nacos服务注册于发现](https://github.com/gmsec/goplugins)\n\n## 安装\n\n- install\n\n- proto环境安装\n\n```\n make install \n```\n\n- 本地环境搭建(gmsec为例)\n\n```\nmake gen\n```\n\n- 新建一个服务\n```\nmake new service=[服务名]\n```\n\n## proto定义\n\n```\nsyntax = \"proto3\"; // 指定proto版本\npackage proto;     // 指定包名\noption go_package = \".;proto\"; // 指定路径\n\n// 定义Hello服务\nservice Hello {\n    // 定义SayHello方法\n    rpc SayHello(HelloRequest) returns (HelloReply) {}\n}\n// HelloRequest 请求结构\nmessage HelloRequest {\n    string name = 1; // 名字\n}\n// HelloReply 响应结构\nmessage HelloReply {\n    string message = 1; // 消息\n}\n```\n\n## 服务端代码示例\n\n``` go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\tproto \"gmsec/rpc/gmsec\"\n\n\t\"github.com/gmsec/goplugins/api\"\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/gmsec/goplugins/plugin\"\n\t\"github.com/gmsec/micro\"\n\t\"github.com/xxjwxc/ginrpc\"\n)\n\nfunc main() {\n\t// grpc 相关 初始化服务\n\tservice := micro.NewService(\n\t\tmicro.WithName(\"lp.srv.eg1\"),\n\t)\n\th := new(hello)\n\tproto.RegisterHelloServer(service.Server(), h) // 服务注册\n\t// ----------- end\n\n\t// gin 相关\n\tbase := ginrpc.New(ginrpc.WithCtx(api.NewAPIFunc), ginrpc.WithDebug(dev.IsDev()))\n\trouter := gin.Default()\n\tv1 := router.Group(\"/xxjwxc/api/v1\")\n\tbase.Register(v1, h) // 对象注册\n\t// ------ end\n\n\tplg, _ := plugin.Run(plugin.WithMicro(service),// grpc 入口\n\t\tplugin.WithGin(router), // http 入口\n        plugin.WithAddr(\":8080\")) // 开始服务(公用端口)\n    \n\tplg.Wait() // 等待结束(ctrl+c)\n    \n\tfmt.Println(\"done\")\n}\n\n// Ctx gin.Context 到 context.Context 的转换\nfunc Ctx(c *gin.Context) interface{} {\n\treturn context.Background()\n}\n```\n\n## 客户端代码:\n\n``` go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\tproto \"gmsec/rpc/gmsec\"\n\n\t\"github.com/gmsec/micro\"\n)\n\nfunc main() {\n    // reg := registry.NewDNSNamingRegistry()\n\t// grpc 相关 注册服务发现等\n\tmicro.NewService(\n        micro.WithName(\"lp.srv.eg1\"),\n        // micro.WithRegisterTTL(time.Second*30),      //指定服务注册时间\n        // micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册\n        // micro.WithRegistryNaming(reg),\n\t)\n\t// ----------- end\n\n\tsay := proto.GetHelloClient()\n\tctx := context.Background()\n\tresp, _ := say.SayHello(ctx, \u0026proto.HelloRequest{Name:\"xxjwxc\"})\n\tfmt.Println(\"result:\", resp)\n}\n```\n\n## 更多示例 =\u003e [传送门](https://github.com/gmsec/gmsec/tree/master/example)\n\n## 正在做\n- etcdv3 \n\n\n## [传送门](https://github.com/gmsec)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmsec%2Fgmsec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmsec%2Fgmsec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmsec%2Fgmsec/lists"}