{"id":13410872,"url":"https://github.com/caarlos0/env","last_synced_at":"2026-02-23T00:22:34.797Z","repository":{"id":35537074,"uuid":"39808208","full_name":"caarlos0/env","owner":"caarlos0","description":"A simple, zero-dependencies library to parse environment variables into structs","archived":false,"fork":false,"pushed_at":"2025-05-05T08:28:11.000Z","size":474,"stargazers_count":5405,"open_issues_count":6,"forks_count":262,"subscribers_count":27,"default_branch":"main","last_synced_at":"2025-05-07T20:28:36.508Z","etag":null,"topics":["config","configuration","environment","environment-variables","go","golang","hacktoberfest"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/caarlos0/env/v11","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/caarlos0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":["caarlos0"]}},"created_at":"2015-07-28T02:14:37.000Z","updated_at":"2025-05-07T19:20:30.000Z","dependencies_parsed_at":"2023-09-24T10:14:48.176Z","dependency_job_id":"5ed92bd3-d3b0-4c9f-977c-13c2cd8661c7","html_url":"https://github.com/caarlos0/env","commit_stats":{"total_commits":357,"total_committers":69,"mean_commits":5.173913043478261,"dds":0.4061624649859944,"last_synced_commit":"e55230b50da897c64fe539fd3bce0887cc1c96bd"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caarlos0%2Fenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caarlos0%2Fenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caarlos0%2Fenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caarlos0%2Fenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caarlos0","download_url":"https://codeload.github.com/caarlos0/env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227603,"owners_count":22035667,"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":["config","configuration","environment","environment-variables","go","golang","hacktoberfest"],"created_at":"2024-07-30T20:01:09.923Z","updated_at":"2026-02-23T00:22:34.774Z","avatar_url":"https://github.com/caarlos0.png","language":"Go","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"GoReleaser Logo\" src=\"https://becker.software/env.png\" height=\"140\" /\u003e\n  \u003cp align=\"center\"\u003eA simple, zero-dependencies library to parse environment variables into structs.\u003c/p\u003e\n\u003c/p\u003e\n\n###### Installation\n\n```bash\ngo get github.com/caarlos0/env/v11\n```\n\n###### Getting started\n\n```go\ntype config struct {\n  Home string `env:\"HOME\"`\n}\n\n// parse\nvar cfg config\nerr := env.Parse(\u0026cfg)\n\n// parse with generics\ncfg, err := env.ParseAs[config]()\n```\n\nYou can see the full documentation and list of examples at [pkg.go.dev](https://pkg.go.dev/github.com/caarlos0/env/v11).\n\n---\n\n## Used and supported by\n\n\u003cp\u003e\n  \u003ca href=\"https://encore.dev\"\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/78424526/214602214-52e0483a-b5fc-4d4c-b03e-0b7b23e012df.svg\" width=\"120px\" alt=\"encore icon\" /\u003e\n  \u003c/a\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cb\u003eEncore – the platform for building Go-based cloud backends.\u003c/b\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n\n## Usage\n\n### Caveats\n\n\u003e [!CAUTION]\n\u003e\n\u003e _Unexported fields_ will be **ignored** by `env`.\n\u003e This is by design and will not change.\n\n### Functions\n\n- `Parse`: parse the current environment into a type\n- `ParseAs`: parse the current environment into a type using generics\n- `ParseWithOptions`: parse the current environment into a type with custom options\n- `ParseAsWithOptions`: parse the current environment into a type with custom options and using generics\n- `Must`: can be used to wrap `Parse.*` calls to panic on error\n- `GetFieldParams`: get the `env` parsed options for a type\n- `GetFieldParamsWithOptions`: get the `env` parsed options for a type with custom options\n\n### Supported types\n\nOut of the box all built-in types are supported, plus a few others that are commonly used.\n\nComplete list:\n\n- `bool`\n- `float32`\n- `float64`\n- `int16`\n- `int32`\n- `int64`\n- `int8`\n- `int`\n- `string`\n- `uint16`\n- `uint32`\n- `uint64`\n- `uint8`\n- `uint`\n- `time.Duration`\n- `time.Location`\n- `encoding.TextUnmarshaler`\n- `url.URL`\n\nPointers, slices and slices of pointers, and maps of those types are also supported.\n\nYou may also add custom parsers for your types.\n\n### Tags\n\nThe following tags are provided:\n\n- `env`: sets the environment variable name and optionally takes the tag options described below\n- `envDefault`: sets the default value for the field\n- `envPrefix`: can be used in a field that is a complex type to set a prefix to all environment variables used in it\n- `envSeparator`: sets the character to be used to separate items in slices and maps (default: `,`)\n- `envKeyValSeparator`: sets the character to be used to separate keys and their values in maps (default: `:`)\n\n### `env` tag options\n\nHere are all the options available for the `env` tag:\n\n- `,expand`: expands environment variables, e.g. `FOO_${BAR}`\n- `,file`: instructs that the content of the variable is a path to a file that should be read\n- `,init`: initialize nil pointers\n- `,notEmpty`: make the field errors if the environment variable is empty\n- `,required`: make the field errors if the environment variable is not set\n- `,unset`: unset the environment variable after use\n\n### Parse Options\n\nThere are a few options available in the functions that end with `WithOptions`:\n\n- `Environment`: keys and values to be used instead of `os.Environ()`\n- `TagName`: specifies another tag name to use rather than the default `env`\n- `PrefixTagName`: specifies another prefix tag name to use rather than the default `envPrefix`\n- `DefaultValueTagName`: specifies another default tag name to use rather than the default `envDefault`\n- `RequiredIfNoDef`: set all `env` fields as required if they do not declare `envDefault`\n- `OnSet`: allows to hook into the `env` parsing and do something when a value is set\n- `Prefix`: prefix to be used in all environment variables\n- `UseFieldNameByDefault`: defines whether or not `env` should use the field name by default if the `env` key is missing\n- `FuncMap`: custom parse functions for custom types\n\n### Documentation and examples\n\nExamples are live in [pkg.go.dev](https://pkg.go.dev/github.com/caarlos0/env/v11),\nand also in the [example test file](./example_test.go).\n\n## Current state\n\n`env` is considered feature-complete.\n\nI do not intent to add any new features unless they really make sense, and are\nrequested by many people.\n\nEventual bug fixes will keep being merged.\n\n## Badges\n\n[![Release](https://img.shields.io/github/release/caarlos0/env.svg?style=for-the-badge)](https://github.com/goreleaser/goreleaser/releases/latest)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge)](/LICENSE.md)\n[![Build status](https://img.shields.io/github/actions/workflow/status/caarlos0/env/build.yml?style=for-the-badge\u0026branch=main)](https://github.com/caarlos0/env/actions?workflow=build)\n[![Codecov branch](https://img.shields.io/codecov/c/github/caarlos0/env/main.svg?style=for-the-badge)](https://codecov.io/gh/caarlos0/env)\n[![Go docs](https://img.shields.io/badge/godoc-reference-blue.svg?style=for-the-badge)](http://godoc.org/github.com/caarlos0/env/v11)\n[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=for-the-badge)](https://github.com/goreleaser)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)\n\n## Related projects\n\n- [envdoc](https://github.com/g4s8/envdoc) - generate documentation for environment variables from `env` tags\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/caarlos0/env.svg)](https://starchart.cc/caarlos0/env)\n","funding_links":["https://github.com/sponsors/caarlos0"],"categories":["Configuration","配置","开源类库","Go","Open source library","配置管理","hacktoberfest","配置管理 `配置解析库`","Uncategorized","Members","Repositories","\u003cspan id=\"组态-configuration\"\u003e组态 Configuration\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","标准CLI","配置","高級控制台界面","Standard CLI","Construction","标准 CLI","高级控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaarlos0%2Fenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaarlos0%2Fenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaarlos0%2Fenv/lists"}