{"id":38799361,"url":"https://github.com/chakradeb/env","last_synced_at":"2026-01-17T12:45:43.393Z","repository":{"id":57539226,"uuid":"288285314","full_name":"chakradeb/env","owner":"chakradeb","description":"A simple golang library to parse environment variables to struct","archived":false,"fork":false,"pushed_at":"2020-08-19T07:54:43.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-01-25T00:13:16.745Z","etag":null,"topics":["environment-variables","golang","parser"],"latest_commit_sha":null,"homepage":"","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/chakradeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-17T21:00:11.000Z","updated_at":"2020-08-18T21:04:49.000Z","dependencies_parsed_at":"2022-09-26T18:31:35.364Z","dependency_job_id":null,"html_url":"https://github.com/chakradeb/env","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/chakradeb/env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chakradeb%2Fenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chakradeb%2Fenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chakradeb%2Fenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chakradeb%2Fenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chakradeb","download_url":"https://codeload.github.com/chakradeb/env/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chakradeb%2Fenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T11:50:55.898Z","status":"ssl_error","status_checked_at":"2026-01-17T11:50:55.569Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["environment-variables","golang","parser"],"created_at":"2026-01-17T12:45:43.283Z","updated_at":"2026-01-17T12:45:43.367Z","avatar_url":"https://github.com/chakradeb.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Env\n\n![Build-Test](https://github.com/chakradeb/env/workflows/Build-Test/badge.svg)\n[![codecov](https://codecov.io/gh/chakradeb/env/branch/master/graph/badge.svg)](https://codecov.io/gh/chakradeb/env)\n\nThis package helps you to parse environment variables using struct\n\n```go\nimport \"github.com/chakradeb/env\"\n```\n\n## Examples\n\nLets start with declaring a couple of environment variables\n\n```shell script\nexport PORT=5000\nexport HOST=localhost\nexport DEBUG=false\n```\n\nNow we will write a `struct` to consume these environment variables\n\n```go\ntype Config struct {\n    Port int `env:\"PORT\"`\n    Host string `env:\"HOST\"`\n    Debug bool `env:\"DEBUG\"`\n}\n```\n\nHere the tag `env` helps the parser to find the variables from environment variables.\nParser will search for the same name in environment variable as provided by `env` tag.\n\nNow, The main function will look something like this\n\n```go\nfunc main() {\n    conf := \u0026Config{}\n\n    errs := env.Parse(conf)\n\n    fmt.Println(\"Port: \", conf.Port)\n    fmt.Println(\"Host: \", conf.Host)\n    fmt.Println(\"Debug: \", conf.Debug)\n}\n```\n\nResult:\n\n```shell script\nPort: 5000\nHost: localhost\nDebug: false\n```\n\n## Supported Struct Tags\n\nFor now `Env` supports only two kind of tags, `env` and `default`.\n\nTag `env` is mandatory to match with the environment variable.\nTag `default` is not mandatory but it is useful to set a default value to a struct field.\n\nFor example, consider these environment variables:\n\n```shell script\nexport HOST=localhost\n```\n\nNow we will declare some default value to our struct field using the `default` tag\n\n```go\ntype Config struct {\n    Port int `env:\"PORT\" default:\"8000\"`\n    Host string `env:\"HOST\" default:\"github.chakradeb.com\"`\n    Debug bool `env:\"DEBUG\" default:\"true\"`\n}\n```\n\nNow we will see the output of our `main` function\n\n```go\nfunc main() {\n    conf := \u0026Config{}\n\n    errs := env.Parse(conf)\n\n    fmt.Println(\"Port: \", conf.Port)\n    fmt.Println(\"Host: \", conf.Host)\n    fmt.Println(\"Debug: \", conf.Debug)\n}\n```\n\nResult:\n\n```shell script\nPort: 8000\nHost: localhost\nDebug: true\n```\n\nAs you can see `Port` and `Debug` has the default value what we've provided using the `default` tag.\n\nBut `Host` didn't get the default value provided in the `default` tag,\nas it is declared in the environment variable already.\n\nSo `default` value will only be effective if there is no environment variable present with the name provided with the `env` tag\n\n## Supported Struct Fields\n\nFor now `Env` supports only these struct field types:\n\n- `string`\n- `int`\n- `int8`\n- `int16`\n- `int32`\n- `int64`\n- `float32`\n- `float64`\n- `bool`\n\nMore support will be added soon\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchakradeb%2Fenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchakradeb%2Fenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchakradeb%2Fenv/lists"}