{"id":27348281,"url":"https://github.com/ruggi/env","last_synced_at":"2025-10-14T22:02:10.273Z","repository":{"id":93995599,"uuid":"105361956","full_name":"ruggi/env","owner":"ruggi","description":"Automatically set Go struct fields values with environment variables","archived":false,"fork":false,"pushed_at":"2017-12-20T22:14:40.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-13T09:58:15.882Z","etag":null,"topics":["env","environment-variables","go","golang","structs"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruggi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2017-09-30T10:18:29.000Z","updated_at":"2017-10-03T07:32:29.000Z","dependencies_parsed_at":"2023-04-26T11:31:44.170Z","dependency_job_id":null,"html_url":"https://github.com/ruggi/env","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ruggi/env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruggi%2Fenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruggi%2Fenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruggi%2Fenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruggi%2Fenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruggi","download_url":"https://codeload.github.com/ruggi/env/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruggi%2Fenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510949,"owners_count":25999012,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["env","environment-variables","go","golang","structs"],"created_at":"2025-04-12T18:17:01.564Z","updated_at":"2025-10-05T20:15:11.159Z","avatar_url":"https://github.com/ruggi.png","language":"Go","readme":"# env\n\n[![godoc](https://godoc.org/github.com/ruggi/env?status.svg)](https://godoc.org/github.com/ruggi/env)\n\nenv tries to set a struct's field values with environment variables' values.\n\nIt comes in handy when dealing with configuration types, inits, tests, benchmarks, etc.\n\n## Usage\n\nThe typical use case is when you have a type with default values but you want to customize some of them at run time without the need for additional code.\n\nWith this prerequisite:\n\n```go\ntype Server struct {\n    Address string `env:\"SERVER_ADDR\"`\n    Port    int    `env:\"SERVER_PORT\"` \n}\n\nfunc init() {\n    srv := \u0026Server{\n        Address: \"localhost\",\n        Port:    8080,\n    }\n    env.ParseInto(srv)\n}\n```\n\nYou can override some (or all) values of `Server` with environment variables named as the `env` tags in the struct's declaration.\n\n```\n$ SERVER_PORT=4567 go run example.go\n```\n\nWhen calling `env.ParseInto` (or the other parsing methods), the interface argument must be a pointer. If it's not, the method returns immediately.\n\nSupported types:\n* string\n* int, int8, int16, int32, int64\n* float32, float64\n* bool\n\nIf the conversion of an environment variable fails, it just skips the field without changing the original value.\n\nYou can support more types with your own conversion function using the `env.ParseTagIntoFunc` method.\n\n### Methods\n\n```go\nfunc ParseInto(c interface{})\n```\nUses the default tag (`\"env\"`) name for convertions.\n\n```go\nfunc ParseTagInto(tag string, c interface{})\n```\nUses a custom tag passed as argument for convertions.\n\n```go\nfunc ParseTagIntoFunc(tag string, c interface{}, convFn ConvFunc)\n```\nUses a custom conversion function when a tag-environment variable match is found, so to allow custom type management. See the [docs](https://godoc.org/github.com/ruggi/env) for more.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruggi%2Fenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruggi%2Fenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruggi%2Fenv/lists"}