{"id":28075250,"url":"https://github.com/cheesycoffee/envparser","last_synced_at":"2025-10-28T08:47:39.981Z","repository":{"id":292688717,"uuid":"981623082","full_name":"cheesycoffee/envparser","owner":"cheesycoffee","description":"A lightweight Go package for parsing environment variables into struct fields using tags","archived":false,"fork":false,"pushed_at":"2025-05-11T15:59:58.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-13T00:55:40.759Z","etag":null,"topics":["env","environment-variables","golang","golang-library","struct","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/cheesycoffee.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":"2025-05-11T14:28:59.000Z","updated_at":"2025-05-11T16:00:01.000Z","dependencies_parsed_at":"2025-05-13T00:55:40.906Z","dependency_job_id":null,"html_url":"https://github.com/cheesycoffee/envparser","commit_stats":null,"previous_names":["cheesycoffee/envparser"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cheesycoffee/envparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheesycoffee%2Fenvparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheesycoffee%2Fenvparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheesycoffee%2Fenvparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheesycoffee%2Fenvparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheesycoffee","download_url":"https://codeload.github.com/cheesycoffee/envparser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheesycoffee%2Fenvparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000955,"owners_count":26082973,"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-09T02:00:07.460Z","response_time":59,"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","golang","golang-library","struct","structs"],"created_at":"2025-05-13T00:55:39.975Z","updated_at":"2025-10-09T07:35:44.132Z","avatar_url":"https://github.com/cheesycoffee.png","language":"Go","readme":"# envparser\n\nA lightweight Go package for parsing environment variables into struct fields using tags, with support for nested/embedded structs and custom decoding.\n\n## Compatibility\n\n- **Go 1.12 or later**  \n  This library is compatible with Go 1.12+ and does not rely on generics or Go modules features introduced after that version.\n\n## ✨ Features\n\n* Simple struct-tag-based configuration\n* Support for various primitive types\n* Nested and embedded structs\n* JSON, XML, Form Data, Base64 decoding via struct tags\n* Custom error aggregation\n* Works with unexported structs in the same package\n\n---\n\n## 🍞 Installation\n\n```bash\ngo get github.com/cheesycoffee/envparser\n```\n\n---\n\n## 🧠 Supported Data Types\n\n| Go Type                                             | Supported           |\n| --------------------------------------------------- | ------------------- |\n| `string`                                            | ✅                   |\n| `int`, `int32`, `int64`                             | ✅                   |\n| `uint`, `uint32`, `uint64`                          | ✅                   |\n| `float32`, `float64`                                | ✅                   |\n| `bool`                                              | ✅                   |\n| `time.Duration`                                     | ✅                   |\n| `time.Time` (RFC3339 format)                        | ✅                   |\n| `[]string`                                          | ✅ (comma-separated) |\n| `[]int`, `[]uint` , `[]uint32`, `[]uint64`.         | ✅ (comma-separated) |\n| `[]float32`, `[]float64`.                           | ✅ (comma-separated) |\n| Structs (anonymous/embedded)                        | ✅                   |\n| Structs with `json`/`xml`/`form`/`base64` tags via `encoding:\"xml\"`/`encoding:\"json\"`/`encoding:\"form\"`/`encoding:\"base64\"` | ✅                   |\n\n---\n\n## 🔧 Usage\n\n### 1. Basic Usage\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\t\"github.com/joho/godotenv\"\n\t\"github.com/cheesycoffee/envparser\"\n)\n\ntype Nested struct {\n    NestedValueString string `env:\"NESTED_VALUE_STRING\"`\n    NestedValueInt    int    `env:\"NESTED_VALUE_INT\"`\n}\n\ntype Embeded struct {\n    EmbededValueString string `env:\"EMBEDED_VALUE_STRING\"`\n    EmbededValueInt    int    `env:\"EMBEDED_VALUE_INT\"`\n}\n\ntype JSONData struct {\n    Name string `json:\"name\"`\n    Age  int    `json:\"age\"`\n}\n\ntype XMLData struct {\n    Name string `xml:\"name\"`\n    Age  int    `xml:\"age\"`\n}\n\ntype Config struct {\n\tAppName       string        `env:\"APP_NAME\"`\n\tPort          int           `env:\"PORT\"`\n\tDebug         bool          `env:\"DEBUG\"`\n    PhiVal        float32       `env:\"PHI_VAL\"`\n\tTimeout       time.Duration `env:\"TIMEOUT\"`\n\tLaunchAt      time.Time     `env:\"LAUNCH_AT\"` // RFC3339 format\n\tAllowedHosts  []string      `env:\"ALLOWED_HOSTS\"`\n\tIDs           []uint64      `env:\"UINT_IDS\"`\n    NestedValue // nested\n    EmbededValue  EmbededValue // embeded\n    JSONData      JSONData      `env:\"JSON_VALUE\" encoding:\"json\"`\n    XMLDATA       XMLDATA       `env:\"XML_VALUE\" encoding:\"xml\"`\n    FormValue     url.Values    `env:\"FORM_VALUE\" encoding:\"form\"`\n    FileData      []byte        `env:\"FILE_VALUE\" encoding:\"base64\"`\n}\n\nfunc main() {\n\t_ = godotenv.Load()\n\n\tvar cfg Config\n\tif err := envparser.Parse(\u0026cfg); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"%+v\\n\", cfg)\n}\n```\n\n### .env Example\n\n```\nAPP_NAME=EnvApp\nPORT=8080\nDEBUG=true\nTIMEOUT=30s\nLAUNCH_AT=\"2023-10-01T15:04:05Z\"\nALLOWED_HOSTS=\"example.com,api.example.com\"\nPHI_VAL=\"3.14\"\nUINT_IDS=\"1,2,4,5\"\nNESTED_VALUE_STRING=\"nested value\"\nNESTED_VALUE_INT=5\nEMBEDED_VALUE_STRING=\"embeded value string\"\nEMBEDED_VALUE_INT=5\nJSON_VALUE=\"{\\\"name\\\":\\\"Alice\\\",\\\"age\\\":30}\"\nXML_VALUE=\"\u003cXMLData\u003e\u003cname\u003eAlice\u003c/name\u003e\u003cage\u003e30\u003c/age\u003e\u003c/XMLData\u003e\"\nFORM_VALUE=\"name=alice\u0026age=30\"\nFILE_VALUE=\"SGVsbG8gR28gd29ybGQh\"\n```\n\n---\n\n## ⚠️ Error Handling\n\nIf multiple fields fail to parse, `Parse` aggregates and returns them all:\n\n```go\nerr := envparser.Parse(\u0026cfg)\nif err != nil {\n\tlog.Fatalf(\"Failed to load config:\\n%v\", err)\n}\n```\n\n---\n\n## 👀 Notes\n\n* Ensure the target is passed as a **pointer to a struct**: `Parse(\u0026cfg)`\n* Environment variable keys must be explicitly defined with `env:\"KEY\"`\n* If a field has no `env` tag or is marked `env:\"-\"`, it will be ignored\n* Embedded/anonymous structs are parsed recursively\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesycoffee%2Fenvparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheesycoffee%2Fenvparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesycoffee%2Fenvparser/lists"}