{"id":28384124,"url":"https://github.com/plaid/go-envvar","last_synced_at":"2025-06-25T22:31:04.770Z","repository":{"id":34247315,"uuid":"38129995","full_name":"plaid/go-envvar","owner":"plaid","description":"A go library for managing environment variables. Maps to typed values, supports required and optional vars with defaults. ","archived":false,"fork":false,"pushed_at":"2020-05-29T09:26:01.000Z","size":32,"stargazers_count":27,"open_issues_count":1,"forks_count":4,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-05-30T08:16:27.155Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Yubico/yubikey-val-dpkg","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plaid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-26T19:35:40.000Z","updated_at":"2025-02-02T17:47:25.000Z","dependencies_parsed_at":"2022-09-02T00:02:17.813Z","dependency_job_id":null,"html_url":"https://github.com/plaid/go-envvar","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/plaid/go-envvar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plaid%2Fgo-envvar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plaid%2Fgo-envvar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plaid%2Fgo-envvar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plaid%2Fgo-envvar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plaid","download_url":"https://codeload.github.com/plaid/go-envvar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plaid%2Fgo-envvar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261962122,"owners_count":23236874,"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":[],"created_at":"2025-05-30T07:38:51.651Z","updated_at":"2025-06-25T22:31:04.752Z","avatar_url":"https://github.com/plaid.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-envvar\n\n[![GoDoc](https://godoc.org/github.com/plaid/go-envvar/envvar?status.svg)](https://godoc.org/github.com/plaid/go-envvar/envvar)\n\nA go library for managing environment variables. It maps environment variables to\ntyped fields in a struct, and supports required and optional vars with defaults.\n\ngo-envvar is inspired by the javascript library https://github.com/plaid/envvar.\n\ngo-envvar supports fields of most primitive types (e.g. int, string, bool,\nfloat64) as well as any type which implements the\n[encoding.TextUnmarshaler](https://golang.org/pkg/encoding/#TextUnmarshaler)\ninterface.\n\n## Example Usage\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/plaid/go-envvar/envvar\"\n)\n\ntype serverEnvVars struct {\n\t// Since we didn't provide a default, the environment variable GO_PORT is\n\t// required. Parse will set the Port field to the value of the environment\n\t// variable and return an error if the environment variable is not set.\n\tPort int `envvar:\"GO_PORT\"`\n\t// Since MaxConns has a default value, it is optional. The value of\n\t// the environment variable, if set, overrides the default value.\n\tMaxConns uint `envvar:\"MAX_CONNECTIONS\" default:\"100\"`\n\t// Similar to GO_PORT, HOST_NAME is required.\n\tHostName string `envvar:\"HOST_NAME\"`\n\t// Time values are also supported. Parse uses the UnmarshalText method of\n\t// time.Time in order to set the value of the field. In this case, the\n\t// UnmarshalText method expects the string value to be in RFC 3339 format.\n\tStartTime time.Time `envvar:\"START_TIME\" default:\"2017-10-31T14:18:00Z\"`\n\t// Duration is supported via time.ParseDuration()\n\tTimeout time.Duration `envvar:\"TIMEOUT\" default:\"30m\"`\n}\n\nfunc main() {\n\tvars := serverEnvVars{}\n\tif err := envvar.Parse(\u0026vars); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// Do something with the parsed environment variables...\n}\n```\n\n### Nested structs\n\ngo-envvar also supports nested structs.\n\n```go\ntype credential struct {\n\tUsername string `envvar:\"USERNAME\"`\n\tPassword string `envvar:\"PASSWORD\"`\n}\n\ntype serverEnvVars struct {\n\tServiceA credential `envvar: \"SERVICE_A_`\n\tServiceB credential `envvar: \"SERVICE_B_`\n}\n\nfunc main() {\n\tvars := serverEnvVars{}\n\terr := envvar.Parse(\u0026vars)\n\t// your application logic\n}\n```\n\nIn this example, envvar `SERVICE_A_USERNAME` will be mapped to the field `vars.ServiceA.Username`.\n`envvar` struct tags on a struct field are interpreted as prefixes for envvar names\nfor the corresponding structs.\n\nInner struct fields can either be a struct, pointer to a struct, or an embedded field.\n\n## Mocking \u0026 Custom behavior.\n\n`ParseWithConfig` can be used to control the behavior of envvar parsing. It supports\n\n* `Getenv` - customize the behavior of obtaining an envvar. By default it uses `syscall.Getenv`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaid%2Fgo-envvar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplaid%2Fgo-envvar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaid%2Fgo-envvar/lists"}