{"id":13713307,"url":"https://github.com/goexl/mengpo","last_synced_at":"2026-01-17T17:24:17.899Z","repository":{"id":53843911,"uuid":"426925769","full_name":"goexl/mengpo","owner":"goexl","description":"Golang default value set library，Go语言默认值配置框架，支持功能：1、设置默认值；2、支持所有Golang内置类型；3、支持JSON配置默认值；4、支持环境变量；5、支持自定义类型；6、支持复杂类型","archived":false,"fork":false,"pushed_at":"2025-05-02T08:02:40.000Z","size":118,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-02T09:22:34.518Z","etag":null,"topics":["default","default-value","defaults","framework","go","golang","setup"],"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/goexl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2021-11-11T08:32:06.000Z","updated_at":"2025-05-02T08:02:43.000Z","dependencies_parsed_at":"2024-06-19T17:34:34.125Z","dependency_job_id":"484afc76-079c-4def-b8e8-78409f4e8f25","html_url":"https://github.com/goexl/mengpo","commit_stats":null,"previous_names":["storezhang/god","storezhang/mengpo"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/goexl/mengpo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goexl%2Fmengpo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goexl%2Fmengpo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goexl%2Fmengpo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goexl%2Fmengpo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goexl","download_url":"https://codeload.github.com/goexl/mengpo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goexl%2Fmengpo/sbom","scorecard":{"id":433696,"data":{"date":"2025-08-11","repo":{"name":"github.com/goexl/mengpo","commit":"654caadaf14dba25bd6e2a4b46799c498b6fce78"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/approve.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":"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":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/approve.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/goexl/mengpo/approve.yml/master?enable=pin","Info:   0 out of   1 third-party GitHubAction 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":"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":"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":"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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"}},{"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":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"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"}}]},"last_synced_at":"2025-08-19T04:03:13.951Z","repository_id":53843911,"created_at":"2025-08-19T04:03:13.951Z","updated_at":"2025-08-19T04:03:13.951Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28512833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: 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":["default","default-value","defaults","framework","go","golang","setup"],"created_at":"2024-08-02T23:01:32.076Z","updated_at":"2026-01-17T17:24:17.883Z","avatar_url":"https://github.com/goexl.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# `mengpo`（孟婆）\n\nGolang默认值设置工具，支持功能\n\n- 支持近乎所有的内置类型\n  - `int`\n  - `int8`\n  - `int32`\n  - `int64`\n  - `uint`\n  - `uint8`\n  - `uint32`\n  - `uint64`\n  - `bool`\n  - `float32`\n  - `float64`\n- 支持复杂类型\n  - `slice`\n  - `map`\n  - `struct`\n- 支持配置\n  - 配置所使用的`tag`名称\n- 支持复杂结构初始化值\n  - 支持`json`初始化值设置\n  - 支持更易于书写的初始化值\n- 支持类型别名\n- 支持指针类型\n- 默认支持`环境变量`\n  - 内置支持`环境变量`语法\n  - 增强型`环境变量`（Substitution）\n    - 默认值\n    - 字符串操作\n    - 长度支持\n- 支持完整的生命周期方法\n  - `Before`\n\n## 为什么要叫孟婆\n\n按照本人的一惯作风，所有项目都在`中国古代神话人物或者历史名人`寻找和项目`意义相近`的`神话人物或者历史人`来做作为项目的名称，原因\n\n- 去TMD`崇洋媚外`\n- 致敬`中华民族的先贤`\n\n`孟婆`作为阴司掌管生死轮回的大神，有将一切人物还原到最被的状态，这和`设置默认值`不谋而和，故而使用`孟婆`来命名项目是合适的\n\u003e\n鸿蒙初开，世间分为天地人三界，天界最大掌管一切，人间即所谓的阳世人界，地即为阴曹地府。三界划定，无论天上地下，神仙阴官，俱都各司其职。孟婆从三界分开时便已在世上，她本为天界的一个散官。后因看到世人恩怨情仇无数，即便死了也不肯放下，就来到了阴曹地府的忘川河边，在奈何桥的桥头立起一口大锅，将世人放不下的思绪炼化成了孟婆汤让阴魂喝下，便忘记了生前的爱恨情仇，卸下了生前的包袱，走入下一个轮回。颇有中国传统思想中“人死如云散”，“一死百了”，“莫记已死之人恩怨”之类的意味。\n\n## 使用方法\n\n### 安装\n\n安装非常简单，推荐使用`go.mod`来使用`孟婆`\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\nfunc main() {\n    // xxx\n}\n```\n\n或者\n\n```shell\ngo get github.com/storezhang/mengpo\n```\n\n### 简单使用\n\n使用非常简单，只需要调用`mengpo.Set`就可以了\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\ntype testByNormal struct {\n    Addr string `default:\"127.0.0.1\"`\n    Port int    `default:\"80\"`\n}\n\nfunc main() {\n    normal := new(testByNormal)\n    if err := mengpo.Set(normal); nil != err {\n        panic(err)\n    }\n}\n```\n\n### 配置标签\n\n可以很方便的使用其它`标签`，方法\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\ntype testByTag struct {\n    Addr string `test:\"127.0.0.1\"`\n    Port int    `test:\"80\"`\n}\n\nfunc main() {\n    tag := new(testByTag)\n    if err := mengpo.Set(tag, mengpo.Tag(`test`)); nil != err {\n        panic(err)\n    }\n}\n```\n\n### 配置复杂类型\n\n可以使用`json`来配置复杂的类型，比如\n\n- `map`\n- `slice`\n- `struct`\n\n`json`写法支持使用单引号`'`来替换转义字符`\\\"`，这样在书写默认值`json`更容易\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\ntype testByJson struct {\n    Orders []string `default:\"['mqtts', 'mqtt', 'wss', 'ws']\"`\n    // 同样支持这样写\n    // Orders []string `default:\"[\\\"mqtts\\\", \\\"mqtt\\\", \\\"wss\\\", \\\"ws\\\"]\"`\n}\n\nfunc main() {\n    json := new(testByJson)\n    if err := mengpo.Set(json); nil != err {\n        panic(err)\n    }\n}\n```\n\n### 使用环境变量\n\n`孟婆`支持使用环境变量来配置默认值\n\n#### 初体验\n\n来一个最简单的环境变量\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\ntype testByEnv struct {\n    Order string `default:\"${ORDER}\"`\n    // 同样支持这种写法\n    // Order string `default:\"$ORDER\"`\n}\n\nfunc main() {\n    env := new(testByEnv)\n    if err := mengpo.Set(env); nil != err {\n        panic(err)\n    }\n}\n```\n\n#### 内置方法（Substitution）\n\n对于环境变量，支持`Substitution`，可以很方便的对`环境变量`做一些变换\n\n| __表达式__                       | __解释__                                |\n|-------------------------------|---------------------------------------\n| `${var}`                      | 取值`$var`\n| `${#var}`                     | 取长度`$var`\n| `${var^}`                     | 首字符大写`$var`\n| `${var^^}`                    | 所有字符大写`$var`\n| `${var,}`                     | 首字符小写`$var`\n| `${var,,}`                    | 所有字符小写`$var`\n| `${var:n}`                    | 从`n`开始取`$var`子串\n| `${var:n:len}`                | 从`n`开始取长度为`len`的`$var`子串\n| `${var#pattern}`              | 从开始跳过最少符合`pattern`的子串\n| `${var##pattern}`             | 从开始跳过最多符合`pattern`的子串\n| `${var%pattern}`              | 从最后跳过最少符合`pattern`的子串\n| `${var%%pattern}`             | 从最后跳过最多符合`pattern`的子串\n| `${var-default`               | 如果`$var`没有设置就取值`$default`\n| `${var:-default`              | 如果`$var`没有设置或者为空就取值`$default`\n| `${var=default`               | 如果`$var`没有设置或者为空就取值`$default`\n| `${var:=default`              | 如果`$var`没有设置或者为空就取值`$default`\n| `${var/pattern/replacement}`  | 替换最少的符合`pattern`的为`replacement`\n| `${var//pattern/replacement}` | 替换最多的符合`pattern`的为`replacement`\n| `${var/#pattern/replacement}` | 从`$var`开始替换符合`pattern`的为`replacement`\n| `${var/%pattern/replacement}` | 从`$var`最后替换符合`pattern`的为`replacement`\n\n#### 嵌套使用\n\n表达式可以嵌套使用，来达到复杂的计算要求\n\n```go\npackage main\n\nimport `github.com/storezhang/mengpo`\n\ntype testByEnv struct {\n    // 应用版本\n    Version string `default:\"${PLUGIN_VERSION=${VERSION=${DRONE_TAG=${DRONE_COMMIT_BRANCH}}}}\"`\n}\n\nfunc main() {\n    env := new(testByEnv)\n    if err := mengpo.Set(env); nil != err {\n        panic(err)\n    }\n}\n```\n\n### 配置处理器\n\n`孟婆`可以很方便的配置值处理器，从而达到更大的扩展性\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"reflect\"\n\n  \"github.com/storezhang/mengpo\"\n)\n\ntype testByBefore struct {\n  Order string `default:\"${ORDER}\"`\n  // 同样支持这种写法\n  // Order string `default:\"$ORDER\"`\n}\n\ntype processor struct{}\n\nfunc (p *processor) Process(tag string, _ reflect.StructField) (to string, err error) {\n  fmt.Printf(`%s, %s`, tag, to)\n\n  return\n}\n\nfunc main() {\n  env := new(testByBefore)\n  if err := mengpo.Set(env, mengpo.Processor(new(processor))); nil != err {\n    panic(err)\n  }\n}\n```\n\n## 捐助\n\n![支持宝](https://github.com/storezhang/donate/raw/master/alipay-small.jpg)\n![微信](https://github.com/storezhang/donate/raw/master/weipay-small.jpg)\n\n## 感谢Jetbrains\n\n本项目通过`Jetbrains开源许可IDE`编写源代码，特此感谢\n[![Jetbrains图标](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png)](https://www.jetbrains.com/?from=goexl/mengpo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoexl%2Fmengpo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoexl%2Fmengpo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoexl%2Fmengpo/lists"}