{"id":13499761,"url":"https://github.com/tomazk/envcfg","last_synced_at":"2026-04-08T15:32:14.750Z","repository":{"id":23919933,"uuid":"27300428","full_name":"tomazk/envcfg","owner":"tomazk","description":"Un-marshaling environment variables to Go structs","archived":false,"fork":false,"pushed_at":"2017-06-19T15:53:22.000Z","size":36,"stargazers_count":103,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T05:32:17.499Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/tomazk/envcfg","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/tomazk.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}},"created_at":"2014-11-29T11:43:53.000Z","updated_at":"2024-03-01T23:44:35.000Z","dependencies_parsed_at":"2022-08-22T07:50:48.501Z","dependency_job_id":null,"html_url":"https://github.com/tomazk/envcfg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomazk/envcfg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomazk%2Fenvcfg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomazk%2Fenvcfg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomazk%2Fenvcfg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomazk%2Fenvcfg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomazk","download_url":"https://codeload.github.com/tomazk/envcfg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomazk%2Fenvcfg/sbom","scorecard":{"id":892211,"data":{"date":"2025-08-11","repo":{"name":"github.com/tomazk/envcfg","commit":"23e3618f1e3368c5fcf78f1e9bc4d09a9362cef9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","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":"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":"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":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"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":"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":"Code-Review","score":0,"reason":"Found 2/21 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":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"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":"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":"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":"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":"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":"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":"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":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"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T12:17:17.534Z","repository_id":23919933,"created_at":"2025-08-24T12:17:17.534Z","updated_at":"2025-08-24T12:17:17.534Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31562688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2024-07-31T22:00:41.427Z","updated_at":"2026-04-08T15:32:14.719Z","avatar_url":"https://github.com/tomazk.png","language":"Go","funding_links":[],"categories":["Configuration","配置","配置管理 `配置解析库`","\u003cspan id=\"组态-configuration\"\u003e组态 Configuration\u003c/span\u003e","配置管理","Uncategorized"],"sub_categories":["Advanced Console UIs","标准CLI","Standard CLI","高级控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高級控制台界面","标准 CLI"],"readme":"# envcfg [![Build Status](https://travis-ci.org/tomazk/envcfg.svg?branch=master)](https://travis-ci.org/tomazk/envcfg)\n\nUn-marshaling environment variables to Go structs\n\n## Getting Started\n\nLet's set a bunch of environment variables and then run your go app\n```bash\n#!/usr/bin/env bash\nexport DEBUG=\"false\"\nexport DB_HOST=\"localhost\"\nexport DB_PORT=\"8012\"\n\n./your_go_app \n```\nWithin your Go app do\n```go\nimport \"github.com/tomazk/envcfg\"\n\n// declare a type that will hold your env variables\ntype Cfg struct {\n\tDEBUG   bool\n\tDB_PORT int\n\tDB_HOST string\n}\n\nfunc main() {\n\tvar config Cfg\n\tenvcfg.Unmarshal(\u0026config)\n\t// config is now set to Config{DEBUG: false, DB_PORT: 8012, DB_HOST: \"localhost\"}\n\t\n\t// optional: clear env variables listed in the Cfg struct\n\tenvcfg.ClearEnvVars(\u0026config)\n}\n```\n## Installation\n\n```\n$ go get github.com/tomazk/envcfg\n```\n\n## Motivation\n\nAs per **[12 factor app manifesto](http://12factor.net/)** configuration of an app should be stored in the [environment](http://12factor.net/config) since it varies between environments by nature. This convention is also dicated and popularized by emerging technologies like docker and cloud platforms. \n\nInstead of having a bunch of `os.Getenv(\"ENV_VAR\")` buried deep in your code when configuring clients and services, **`envcfg`** encourages you to:\n\n1. **define a struct type** that will hold your environment variables and serve as documentation which env variables must be configured\n2. use **`envcfg.Unmarshal`** to read your env variables and unmarhsal them to an object that now holds your configuration of an app\n3. use **`envcfg.ClearEnvVars`** to unset env variables, removing potential vulnerability of passing secrets to unsafe child processes or vendor libraries that assume you're not storing unsafe values in the environment\n\n## Documentation\n\n### `envcfg.Unmarshal`\n\n`func Unmarshal(v interface{}) error` can recieve a reference to an object or even a reference to a pointer:\n\n```go\nvar val2 StructType\nenvcfg.Unmarshal(\u0026val2)\n\nvar val1 *StructType \nenvcfg.Unmarshal(\u0026val1) // val1 will be initialized\n```\n\n#### Supported Struct Field Types \n\n`envcfg.Unmarshal` supports `int`, `string`, `bool` and `[]int`, `[]string`, `[]bool` types of fields wihin a struct. In addition, fields that satisfy the `encoding.TextUnmarshaler` interface are also supported. `envcfg.Unmarshal` will return nil if a valid struct was passed or return an error if not.\n\n```go\ntype StructType struct {\n\tINT           int\n\tBOOL          bool\n\tSTRING        string\n\tSLICE_STRING  []string\n\tSLICE_BOOL    []bool\n\tSLICE_INT     []int\n\tCUSTOM_TYPE   MyType\n}\n\ntype MyType struct{}\nfunc (mt *MyType) UnmarshalText(text []byte) error {\n\t...\n}\n```\n#### Validation\n`envcfg.Unmarshal` also spares you from writing type validation code:\n\n```go\ntype StructType struct {\n\tSHOULD_BE_INT int\n}\n```\nIf you'll pass `export SHOULD_BE_INT=\"some_string_value\"` to your application `envcfg.Unmarshal` will return an error.\n\n#### Struct Tags for Custom Mapping of env Variables\nYou can also use struct field tags to map env variables to fields wihin a struct\n```bash\nexport MY_ENV_VAR=1\n```\n```go\ntype StructType struct {\n\tField int `envcfg:\"MY_ENV_VAR\"`\n}\n```\n#### Slices Support\n`envcfg.Unmarshal` also supports `[]int`, `[]string`, `[]bool` slices. Values of the slice are ordered in respect to env name suffix. See example below.\n```bash\nexport CASSANDRA_HOST_1=\"192.168.0.20\" # *_1 will come as the first element of the slice\nexport CASSANDRA_HOST_2=\"192.168.0.21\"\nexport CASSANDRA_HOST_3=\"192.168.0.22\"\n```\n```go\ntype StructType struct {\n\tCASSANDRA_HOST []string\n}\nfunc main() {\n\tvar config StructType\n\tenvcfg.Unmarshal(\u0026config)\n\t// config.CASSANDRA_HOST is now set to []string{\"192.168.0.20\", \"192.168.0.21\", \"192.168.0.22\"} \n}\n```\n### `envcfg.ClearEnvVars`\n\n`func ClearEnvVars(v interface{}) error` recieves a reference to the same struct you've passed to `envcfg.Unmarshal` and it will unset any environment variables listed in the struct. Except for those that you want to keep and are tagged with `envcfgkeep:\"\"` struct field tag. It will throw an error on unsupported types.\n\n```bash\nexport SECRET_AWS_KEY=\"foobar\" \nexport PORT=\"8080\" \n```\n```go\ntype StructType struct {\n\tSECRET_AWS_KEY string\n\tPORT           int    `envcfgkeep:\"\"`\n}\nfunc main() {\n\tvar config StructType\n\tenvcfg.ClearEnvVars(\u0026config)\n\t// it will unset SECRET_AWS_KEY but keep env variable PORT\n}\n```\n\n\n## Contributing\nSend me a pull request and make sure tests pass on [travis](https://travis-ci.org/tomazk/envcfg/).\n\n## Tests\n\nPackage comes with an extensive test suite that's continuously run on travis against go versions: 1.3, 1.4, 1.5, 1.6, 1.7, 1.8 and the development tip.\n```\n$ go test github.com/tomazk/envcfg\n```\n\n## Licence\n\nSee LICENCE file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomazk%2Fenvcfg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomazk%2Fenvcfg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomazk%2Fenvcfg/lists"}