{"id":42639125,"url":"https://github.com/infraboard/mcube","last_synced_at":"2026-01-29T06:08:30.668Z","repository":{"id":38157603,"uuid":"220629310","full_name":"infraboard/mcube","owner":"infraboard","description":"微服务工具箱","archived":false,"fork":false,"pushed_at":"2025-11-23T11:44:15.000Z","size":1630,"stargazers_count":140,"open_issues_count":7,"forks_count":56,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-11-23T13:14:00.123Z","etag":null,"topics":["ddd-architecture","http-framework","http-router","middlewares","mircoservices","restful-webservices"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infraboard.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-11-09T11:00:09.000Z","updated_at":"2025-11-23T11:43:55.000Z","dependencies_parsed_at":"2023-02-03T16:46:29.476Z","dependency_job_id":"b9e4543d-39e3-4b16-afa3-69eeb13ab891","html_url":"https://github.com/infraboard/mcube","commit_stats":{"total_commits":429,"total_committers":1,"mean_commits":429.0,"dds":0.0,"last_synced_commit":"774eb6a99ea7230d4699f2bf4d36dcb8e85df853"},"previous_names":[],"tags_count":288,"template":false,"template_full_name":null,"purl":"pkg:github/infraboard/mcube","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infraboard%2Fmcube","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infraboard%2Fmcube/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infraboard%2Fmcube/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infraboard%2Fmcube/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infraboard","download_url":"https://codeload.github.com/infraboard/mcube/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infraboard%2Fmcube/sbom","scorecard":{"id":488465,"data":{"date":"2025-08-11","repo":{"name":"github.com/infraboard/mcube","commit":"52c9c698f5d4370321820c2e729a78011d1da6b3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":10,"reason":"22 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/infraboard/mcube/main.yml/master?enable=pin","Warn: goCommand not pinned by hash: .github/workflows/main.yml:26","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T18:25:56.208Z","repository_id":38157603,"created_at":"2025-08-19T18:25:56.208Z","updated_at":"2025-08-19T18:25:56.208Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28865391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T05:56:06.453Z","status":"ssl_error","status_checked_at":"2026-01-29T05:55:57.668Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ddd-architecture","http-framework","http-router","middlewares","mircoservices","restful-webservices"],"created_at":"2026-01-29T06:08:30.098Z","updated_at":"2026-01-29T06:08:30.652Z","avatar_url":"https://github.com/infraboard.png","language":"Go","readme":"# mcube\n[![Go Report Card](https://goreportcard.com/badge/github.com/infraboard/mcube)](https://goreportcard.com/report/github.com/infraboard/mcube/v2)\n[![Release](https://img.shields.io/github/release/infraboard/mcube.svg?style=flat-square)](https://github.com/infraboard/mcube/releases)\n[![MIT License](https://img.shields.io/github/license/infraboard/mcube.svg)](https://github.com/infraboard/mcube/blob/master/LICENSE)\n\n[官方文档](https://www.mcube.top/docs/framework/)\n\nmcube是一款用于构建渐进式微服务(单体--\u003e微服务)的框架, 让应用从单体无缝过渡到微服务, 同时提供丰富的配置即用的功能配置, \n只需简单配置就可拥有:\n+ Log: 支持文件滚动和Trace的日志打印\n+ Metric: 支持应用自定义指标监控\n+ Trace: 集成支持完整的全链路追踪(HTTP Server/GRPC Server/数据库...)以及自定义埋点\n+ CORS: 资源跨域共享\n+ Health Check: HTTP 和 GRPC 健康检查\n+ API DOC: 基于Swagger的 API 文档\n\n除了上面这些功能配置，还会用到很多三方工具, 也是配置即用:\n+ MySQL: Grom集成\n+ MongoDB 官方驱动集成\n+ Redis: go-redis集成\n+ Kafka: kafka-go集成\n+ 分布式缓存: 当前只适配了Redis\n+ 分布式锁: 当前只适配了Redis\n\n![框架架构](./docs/ioc/arch.png)\n\n## 快速开始\n\n下面是演示一个TestObject对象的注册与获取的基础功能:\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/infraboard/mcube/v2/ioc\"\n\t\"github.com/infraboard/mcube/v2/ioc/config/datasource\"\n\tioc_gin \"github.com/infraboard/mcube/v2/ioc/config/gin\"\n\t\"github.com/infraboard/mcube/v2/ioc/server\"\n\t\"gorm.io/gorm\"\n\n\t// 开启Health健康检查\n\t_ \"github.com/infraboard/mcube/v2/ioc/apps/health/gin\"\n\t// 开启Metric\n\t_ \"github.com/infraboard/mcube/v2/ioc/apps/metric/gin\"\n)\n\nfunc main() {\n\t// 注册HTTP接口类\n\tioc.Api().Registry(\u0026ApiHandler{})\n\n\t// 开启配置文件读取配置\n\tserver.DefaultConfig.ConfigFile.Enabled = true\n\tserver.DefaultConfig.ConfigFile.Path = \"etc/application.toml\"\n\n\t// 启动应用\n\terr := server.Run(context.Background())\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\ntype ApiHandler struct {\n\t// 继承自Ioc对象\n\tioc.ObjectImpl\n\n\t// mysql db依赖\n\tdb *gorm.DB\n}\n\n// 覆写对象的名称, 该名称名称会体现在API的路径前缀里面\n// 比如: /simple/api/v1/module_a/db_stats\n// 其中/simple/api/v1/module_a 就是对象API前缀, 命名规则如下:\n// \u003cservice_name\u003e/\u003cpath_prefix\u003e/\u003cobject_version\u003e/\u003cobject_name\u003e\nfunc (h *ApiHandler) Name() string {\n\treturn \"module_a\"\n}\n\n// 初始化db属性, 从ioc的配置区域获取共用工具 gorm db对象\nfunc (h *ApiHandler) Init() error {\n\th.db = datasource.DB()\n\n\t// 进行业务暴露, router 通过ioc\n\trouter := ioc_gin.RootRouter()\n\trouter.GET(\"/db_stats\", h.GetDbStats)\n\treturn nil\n}\n\n// 业务功能\nfunc (h *ApiHandler) GetDbStats(ctx *gin.Context) {\n\tdb, _ := h.db.DB()\n\tctx.JSON(http.StatusOK, gin.H{\n\t\t\"data\": db.Stats(),\n\t})\n}\n```\n\n程序配置: etc/application.toml\n```toml\n[app]\nname = \"simple\"\nkey  = \"this is your app key\"\n\n[http]\nhost = \"127.0.0.1\"\nport = 8020\n\n[datasource]\nhost = \"127.0.0.1\"\nport = 3306\nusername = \"root\"\npassword = \"123456\"\ndatabase = \"test\"\n\n[log]\nlevel = \"debug\"\n\n[log.file]\nenable = true\n```\n\n运行程序: [完整代码示例](https://github.com/infraboard/mcube/tree/master/examples/simple)\n```sh\n➜  simple git:(master) go run main.go \n2025/08/20 20:59:12 init app app[priority: 999] ok.\n2025/08/20 20:59:12 init app trace[priority: 998] ok.\n2025/08/20 20:59:12 init app log[priority: 997] ok.\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n[GIN-debug] [WARNING] Running in \"debug\" mode. Switch to \"release\" mode in production.\n - using env:   export GIN_MODE=release\n - using code:  gin.SetMode(gin.ReleaseMode)\n\n2025-08-20T20:59:12+08:00 INFO   config/gin/framework.go:41 \u003e enable gin recovery component:GIN_WEBFRAMEWORK\n2025/08/20 20:59:12 init app gin_webframework[priority: 898] ok.\n2025/08/20 20:59:12 init app datasource[priority: 699] ok.\n2025/08/20 20:59:12 init app grpc[priority: -89] ok.\n2025/08/20 20:59:12 init app http[priority: -99] ok.\n[GIN-debug] GET    /metrics/                 --\u003e github.com/infraboard/mcube/v2/ioc/apps/metric/gin.(*ginHandler).Registry.func1 (5 handlers)\n2025-08-20T20:59:12+08:00 INFO   metric/gin/metric.go:89 \u003e Get the Metric using http://127.0.0.1:8020/metrics component:METRIC\n2025/08/20 20:59:12 init app metric[priority: 99] ok.\n[GIN-debug] GET    /healthz/                 --\u003e github.com/infraboard/mcube/v2/ioc/apps/health/gin.(*HealthChecker).HealthHandleFunc-fm (5 handlers)\n2025-08-20T20:59:12+08:00 INFO   health/gin/check.go:55 \u003e Get the Health using http://127.0.0.1:8020/healthz component:HEALTH_CHECK\n2025/08/20 20:59:12 init app health[priority: 0] ok.\n[GIN-debug] GET    /db_stats                 --\u003e main.(*ApiHandler).GetDbStats-fm (5 handlers)\n2025/08/20 20:59:12 init app module_a[priority: 0] ok.\n2025-08-20T20:59:12+08:00 INFO   ioc/server/server.go:76 \u003e loaded configs: [app.v1 trace.v1 log.v1 gin_webframework.v1 datasource.v1 grpc.v1 http.v1] component:SERVER\n2025-08-20T20:59:12+08:00 INFO   ioc/server/server.go:76 \u003e loaded default: [] component:SERVER\n2025-08-20T20:59:12+08:00 INFO   ioc/server/server.go:76 \u003e loaded controllers: [] component:SERVER\n2025-08-20T20:59:12+08:00 INFO   ioc/server/server.go:76 \u003e loaded apis: [metric.v1 health.v1 module_a.v1] component:SERVER\n2025-08-20T20:59:12+08:00 INFO   config/http/http.go:144 \u003e HTTP服务启动成功, 监听地址: 127.0.0.1:8020 component:HTTP\n```\n\n## 应用开发\n\n### 标准化工程配置\n\n统一了项目的配置加载方式:\n\n环境变量\n配置文件\nTOML\nYAML\nJSON\n下面是项目配置文件(etc/application.toml)内容:\n\n```toml\n[app]\nname = \"simple\"\nkey  = \"this is your app key\"\n\n[http]\nhost = \"127.0.0.1\"\nport = 8020\n\n[datasource]\nhost = \"127.0.0.1\"\nport = 3306\nusername = \"root\"\npassword = \"123456\"\ndatabase = \"test\"\n\n[log]\nlevel = \"debug\"\n\n[log.file]\nenable = true\nfile_path = \"logs/app.log\"\n```\n\n### 即插即用的组件\n\n通过简单的配置就能为项目添加:\n\n检查检查(Health Chcek)\n应用指标监控(Metric)\n\n```go\nimport (\n  // 开启Health健康检查\n  _ \"github.com/infraboard/mcube/v2/ioc/apps/health/gin\"\n  // 开启Metric\n  _ \"github.com/infraboard/mcube/v2/ioc/apps/metric/gin\"\n)\n```\n\n启动过后, 在日志里就能看到这2个功能开启了:\n```sh\n2024-01-05T11:30:00+08:00 INFO   health/gin/check.go:52 \u003e Get the Health using http://127.0.0.1:8020/healthz component:HEALTH_CHECK\n2024-01-05T11:30:00+08:00 INFO   metric/gin/metric.go:51 \u003e Get the Metric using http://127.0.0.1:8020/metrics component:METRIC\n```\n\n当然你也可以通过配置来修改功能的URL路径:\n```toml\n[health]\n  path = \"/healthz\"\n\n[metric]\n  enable = true\n  provider = \"prometheus\"\n  endpoint = \"/metrics\"\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfraboard%2Fmcube","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfraboard%2Fmcube","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfraboard%2Fmcube/lists"}