{"id":44276488,"url":"https://github.com/potproject/goenvgen","last_synced_at":"2026-02-10T20:36:16.464Z","repository":{"id":57639705,"uuid":"427219073","full_name":"potproject/goenvgen","owner":"potproject","description":"Automatically generate Go Code from dotenv files.","archived":false,"fork":false,"pushed_at":"2023-12-10T14:53:27.000Z","size":56,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T11:58:42.247Z","etag":null,"topics":["dotenv","go","go-generate","golang"],"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/potproject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-11-12T03:23:02.000Z","updated_at":"2024-03-23T06:33:15.000Z","dependencies_parsed_at":"2023-12-10T15:47:14.910Z","dependency_job_id":null,"html_url":"https://github.com/potproject/goenvgen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/potproject/goenvgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potproject%2Fgoenvgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potproject%2Fgoenvgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potproject%2Fgoenvgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potproject%2Fgoenvgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/potproject","download_url":"https://codeload.github.com/potproject/goenvgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potproject%2Fgoenvgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29314884,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T17:48:59.043Z","status":"ssl_error","status_checked_at":"2026-02-10T17:45:37.240Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["dotenv","go","go-generate","golang"],"created_at":"2026-02-10T20:36:15.324Z","updated_at":"2026-02-10T20:36:16.449Z","avatar_url":"https://github.com/potproject.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goenvgen [![Go](https://github.com/potproject/goenvgen/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/potproject/goenvgen/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/potproject/goenvgen/branch/master/graph/badge.svg?token=FWVQKED8BO)](https://codecov.io/gh/potproject/goenvgen) [![Go Report Card](https://goreportcard.com/badge/github.com/potproject/goenvgen)](https://goreportcard.com/report/github.com/potproject/goenvgen)\n\nAutomatically generate Go Code from dotenv files.\n\nThis cli automatically determines the type information from the dotenv information and generates a Go package that can retrieve it.\n`os.GetEnv` the code becomes complicated because of the lack of type information.\nThis package eliminates the need to use `os.GetEnv`.\n\n## Usage\n\n### Installation\n\n```\n# Go \u003e= 1.17:\n$ go install github.com/potproject/goenvgen\n\n# Go \u003c 1.17:\n$ go get github.com/potproject/goenvgen\n```\n\n### Generate Code\n\nAdd your application configuration to your `.env` file in the root of your project.\n\n```\nBASE_HOST=localhost\nBASE_PORT=8080\nADMIN_IDS=123,234,345,456\n\nUSER_JSON={\"Alice\": {\"ID\": 100}, \"Bob\": {\"ID\": 200}}\n```\n\nThe following code will be generated automatically Go Package.\n\n```\n$ goenvgen -p envgen .env\nGenerated envgen Packages.\n\n$ tree envgen\nenvgen\n├── USER_JSON.go\n└── envgen.go\n```\n\n### About generated package\n\nThis package itself does not read environment variables from dotenv, so [joho/godotenv](https://github.com/joho/godotenv) is required if you want to use .env file.\n\nThis is because it may control whether the dotenv file is loaded in the production and development environments.\n\n#### Example Codes:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/joho/godotenv\"\n\t\"[Your package path]/envgen\"\n)\n\nfunc main() {\n\t// Loading .env file\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tlog.Fatal(\"Error loading .env file\")\n\t}\n\n\t// Setup envgen package from environment variables\n\terr = envgen.Load()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Getting Environment Variables\n\thost := envgen.Get().BASE_HOST()\n\tport := envgen.Get().BASE_PORT()\n\tfmt.Printf(\"Running to http://%s:%d/\", host, port)\n  \n\t// Slice Type\n\tids := envgen.Get().ADMIN_IDS()\n\tfor _, id := range ids {\n\t\tfmt.Printf(\"ID: %d \\r\\n\", id)\n\t}\n\n\t// JSON Type\n\tuser := envgen.Get().USER_JSON()\n\tfmt.Printf(\"Bod ID: %d \\r\\n\", user.Bob.ID)\n}\n\n```\n\n#### Results:\n```bash\n$ go run main.go\nRunning to http://localhost:8080/\nID: 123 \nID: 234\nID: 345\nID: 456\nBob ID: 200\n```\n\nEnjoy Development!\n\n## Details\n\n```\nUsage of envgen:\n  -p string\n        the name of the package for the generated code (default \"envgen\")\n  -r string\n        Required Type setting (example: \"-r ENV_REQ_BOOL,ENV_REQ_STRING\")\n  -t string\n        Manually type definition setting (example: \"-t ENV_BOOL=bool,ENV_S_INT=[]int\")\n```\n\n### Automatic determination of type\n\nAt the time of code generation, the type is automatically assigned from the values in the .env file.\n\nAutomatic generation is generated by the following rule.\n\n|  value  |  is Type ...  | Example |\n| ---- | ---- | ---- |\n| JSON strings  |  Generate struct for [ChimeraCoder/gojson](https://github.com/ChimeraCoder/gojson)  | '{\"Alice\": {\"ID\": 100}, \"Bob\": {\"ID\": 200}}' |\n| `true` or `false`  |  `boolean`  | 'true' |\n| integral number  |  `int64`  | '123' |\n| floating point number | `float64` | '1.1' |\n| `true` or `false` with comma | `[]boolean` | 'true,false' |\n| integral number with comma | `[]int64` | '100,200' |\n| floating point number with comma | `[]float64` | '0.1,0.2' |\n| charactor with comma | `[]string` | 'string1,string2' |\n| otherwise | `string` | 'string' |\n\n### Manual determination of type\n\nThe type can be set manually by specifying the `-t` option when generating the code.\n\nThe types that can be set are `bool`, `int`, `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `uint32`, `uint64`, `float32`, `float64`, `interface`, and `string`. or their slice types.\n\n#### Example:\n```\ngoenvgen -p envgen -t BASE_PORT=uint16,ADMIN_IDS=[]int\n```\n\n### Required Environment Variable\n\nYou can make the value required by specifying the `-r` option when generating the code.\n\n#### Example:\n```\nBASE_HOST=\nBASE_PORT=8080\n```\n\n```\ngoenvgen -p envgen -r BASE_HOST,BASE_PORT\n```\n\n```bash\n$ go run .\\main.go\nBASE_HOST is required\n```\n\n## Development \u0026 Contributing\n\nContributions are most welcome!\n\n```bash\n$ git clone https://https://github.com/potproject/goenvgen.git\n\n# Code Generating Test\n$ cd test\n$ vi .env.test # Change .env.test File\n$ go run main.go\n$ go test ./envgentest/\n```\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotproject%2Fgoenvgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotproject%2Fgoenvgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotproject%2Fgoenvgen/lists"}