{"id":17332562,"url":"https://github.com/profclems/go-dotenv","last_synced_at":"2025-07-25T18:39:00.765Z","repository":{"id":48960545,"uuid":"310933394","full_name":"profclems/go-dotenv","owner":"profclems","description":"A minimalist library for reading and writing .env files in Go","archived":false,"fork":false,"pushed_at":"2024-09-10T11:23:53.000Z","size":64,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-10T12:53:18.525Z","etag":null,"topics":["configuration","environment-variables","go","golang","golang-library","hacktoberfest","hacktoberfest2021"],"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/profclems.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":"2020-11-07T21:16:43.000Z","updated_at":"2024-09-10T11:23:22.000Z","dependencies_parsed_at":"2024-09-10T12:47:27.485Z","dependency_job_id":"f9f10096-14f2-4074-8c35-767e1300b0d8","html_url":"https://github.com/profclems/go-dotenv","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"20fe493eea17a4811f6d00caff7b138dee397af2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profclems%2Fgo-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profclems%2Fgo-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profclems%2Fgo-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profclems%2Fgo-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profclems","download_url":"https://codeload.github.com/profclems/go-dotenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219843550,"owners_count":16556504,"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":["configuration","environment-variables","go","golang","golang-library","hacktoberfest","hacktoberfest2021"],"created_at":"2024-10-15T14:58:07.449Z","updated_at":"2024-10-15T14:58:07.957Z","avatar_url":"https://github.com/profclems.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dotenv [![Go Report Card](https://goreportcard.com/badge/github.com/profclems/go-dotenv)](https://goreportcard.com/report/github.com/profclems/go-dotenv) [![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/profclems/go-dotenv)](https://pkg.go.dev/mod/github.com/profclems/go-dotenv)\n\nDotenv is a minimal Go Library for reading .env configuration files.\n\nDotenv reads config in the following order. Each item takes precedence over the item below it:\n\n- env\n- key-value config cache/store (loaded from the .env file or set explicitly)\n- default (when using structures)\n\nThe config cache store is set on first read operation.\n\n```sh\nBenchmarkDotenv_Load-12            57186             19774 ns/op           17477 B/op         89 allocs/op\nBenchmarkDotenv_instance/Get-12                         30091465                39.93 ns/op            0 B/op          0 allocs/op\nBenchmarkDotenv_instance/Get_NotExist-12                24608632                48.31 ns/op            0 B/op          0 allocs/op\nBenchmarkDotenv_instance/Set-12                         52317692                23.51 ns/op            0 B/op          0 allocs/op\nBenchmarkDotenv_global/Get-12                           25803398                46.73 ns/op            0 B/op          0 allocs/op\nBenchmarkDotenv_global/Get_NotExist-12                  20868642                59.51 ns/op            0 B/op          0 allocs/op\nBenchmarkDotenv_global/Set-12                           37934266                32.20 ns/op            0 B/op          0 allocs/op\n```\n\n## Installation\n\n```sh\ngo get -u github.com/profclems/go-dotenv\n```\n\n## Usage\n\nAssuming you have a .env file in the current directory with the following values\n```env\nS3_BUCKET=yours3bucket\nSECRET_KEY=yoursecretKey\nPRIORITY_LEVEL=2\n```\n\nThen in your Go application, you can do something like this:\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \n    \"github.com/profclems/go-dotenv\"\n)\n\nfunc main() {\n  // .env - It will search for the .env file in the current directory and load it. \n  // You can explicitly set config file with dotenv.SetConfigFile(\"path/to/file.env\")\n  err := dotenv.Load()\n  if err != nil {\n    log.Fatalf(\"Error loading .env file: %v\", err)\n  }\n\n  s3Bucket := dotenv.GetString(\"S3_BUCKET\")\n  secretKey := dotenv.GetString(\"SECRET_KEY\")\n  priorityLevel := dotenv.GetInt(\"PRIORITY_LEVEL\")\n\n  // now do something with s3 or whatever\n}\n```\n\nComments and exports are supported:\n```dotenv\n# This is a comment\nS3_BUCKET=yours3bucket\nSECRET_KEY=yoursecretKey # This is also a comment\nexport PRIORITY_LEVEL=2\n```\n\nAll the above examples use the global DotEnv instance. You can instantiate a new Dotenv instance:\n\n```go\ncfg := dotenv.New()\ncfg.SetConfigFile(\"path/to/.env\")\nerr := cfg.Load()\nif err != nil {\n\tlog.Fatalf(\"Error loading .env file: %v\", err)\n}\n\nval := cfg.GetString(\"SOME_ENV\")\n```\n\n### Getting Values From DotEnv\nThe following functions and methods exist to get a value depending the Type:\n\n- `Get(key string) : any`\n- `GetString(key string) : string`\n- `GetBool(key string) : bool`\n- `GetFloat64(key string) : float64`\n- `GetInt(key string) : int`\n- `GetIntSlice(key string) : []int`\n- `GetStringSlice(key string) : []string`\n- `GetTime(key string) : time.Time`\n- `GetDuration(key string) : time.Duration`\n- `isSet(key string) : bool`\n- `LookUp(key string) : (any, bool)`\n- `Set(key string, value any)`\n\n## Contributing\nContributions are most welcome! It could be a new feature, bug fix, refactoring or even reporting an issue.\n\n- Fork it\n- Create your feature branch (git checkout -b my-new-feature)\n- Commit your changes (git commit -am 'Added some feature')\n- Push to the branch (git push origin my-new-feature)\n- Create new Pull Request\n\n## License\nCopyright © [Clement Sam](http://twitter.com/clems_dev)\n\nThis package is open-sourced software licensed under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofclems%2Fgo-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofclems%2Fgo-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofclems%2Fgo-dotenv/lists"}