{"id":18745414,"url":"https://github.com/yassinebenaid/dotenv","last_synced_at":"2025-07-07T08:39:31.449Z","repository":{"id":221701168,"uuid":"754777845","full_name":"yassinebenaid/dotenv","owner":"yassinebenaid","description":"Go Library to read environment variables from .env file.","archived":false,"fork":false,"pushed_at":"2024-03-01T10:12:49.000Z","size":24,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T15:54:35.586Z","etag":null,"topics":["environment-variables","go","library"],"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/yassinebenaid.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}},"created_at":"2024-02-08T18:46:09.000Z","updated_at":"2024-04-19T21:44:21.000Z","dependencies_parsed_at":"2024-02-09T15:44:11.097Z","dependency_job_id":"6c3e6536-c967-4523-9f9b-d02a19673444","html_url":"https://github.com/yassinebenaid/dotenv","commit_stats":null,"previous_names":["yassinebenaid/dotenv"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yassinebenaid","download_url":"https://codeload.github.com/yassinebenaid/dotenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636327,"owners_count":21137428,"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":["environment-variables","go","library"],"created_at":"2024-11-07T16:18:01.576Z","updated_at":"2025-04-12T21:32:51.369Z","avatar_url":"https://github.com/yassinebenaid.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotenv\n\nGo Library to read environment variables from .env file.\n\n[![Tests](https://github.com/yassinebenaid/dotenv/actions/workflows/tests.yaml/badge.svg)](https://github.com/yassinebenaid/dotenv/actions/workflows/tests.yaml)\n[![Version](https://badge.fury.io/gh/yassinebenaid%2Fdotenv.svg)](https://badge.fury.io/gh/yassinebenaid%2Fdotenv)\n[![AGPL License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENCE)\n\n# Usage\n\ninstall the library :\n\n```bash\ngo get -u github.com/yassinebenaid/dotenv\n```\n\n_.env_\n\n```bash\n# comments are supported\n\nPORT=8080\nHOST=\"example.com:$PORT\" # inline comments too\n\n```\n\nthen in the beginning of your program, preferrably in the `main` function:\n\n_main.go_\n\n```go\npackage main\n\nimport (\n    \"os\"\n    \"fmt\"\n\n    \"github.com/yassinebenaid/dotenv\"\n)\n\nfunc main(){\n    err := dotenv.Load(false,\".env\")\n    if err != nil{\n        panic(err)\n    }\n\n    fmt.Println(os.Getenv(\"PORT\")) // 8080\n    fmt.Println(os.Getenv(\"HOST\")) // example.com:8080\n\n\n    // if no file path provided, Load will default\n    // to loading .env in current working directory\n    err = dotenv.Load(false)\n    if err != nil{\n        panic(err)\n    }\n\n    fmt.Println(os.Getenv(\"PORT\")) // 8080\n    fmt.Println(os.Getenv(\"HOST\")) // example.com:8080\n\n    // ...\n}\n``\n```\n\n# API\n\n## dotenv.Load\n\n_.env_\n\n```bash\nPORT=8080\nHOST=\"example.com:$PORT\"\n\n```\n\n_main.go_\n\n```go\npackage main\n\nimport (\n    \"os\"\n    \"fmt\"\n\n    \"github.com/yassinebenaid/dotenv\"\n)\n\nfunc main(){\n    os.Setenv(\"PORT\",\"5000\")\n\n    err := dotenv.Load(false) // will not override\n    if err != nil{\n        panic(err)\n    }\n\n    fmt.Println(os.Getenv(\"PORT\")) // 5000\n\n\n    // if you want to override\n     os.Setenv(\"PORT\",\"5000\")\n\n    err = dotenv.Load(true) // will  override\n    if err != nil{\n        panic(err)\n    }\n\n    fmt.Println(os.Getenv(\"PORT\")) // 8080\n\n    // you can pass multiple files\n    err = dotenv.Load(true,\"./path/to/file-1\",\"./path/to/file-2\")\n    if err != nil{\n        panic(err)\n    }\n}\n``\n```\n\n## dotenv.Read\n\n_main.go_\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/yassinebenaid/dotenv\"\n)\n\nfunc main() {\n\tenv, err := dotenv.Read(\"/path/to/.env\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(env[\"PORT\"])\n\n\t// you can pass multiple files\n\tenv, err = dotenv.Read(\"/path/to/.env-1\", \"/path/to/.env-2\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// if not path provided, Read will default to loading .env in current\n\t// working directory\n\tenv, err = dotenv.Read()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n}\n\n``\n```\n\n`\n\n## dotenv.Unmarshal\n\n_main.go_\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/yassinebenaid/dotenv\"\n)\n\nfunc main(){\n    input := []byte(`\n        KEY_1=value\n        KEY_2=value\n    `)\n    env,err := dotenv.Unmarshal(input)\n    if err != nil{\n        panic(err)\n    }\n\n    fmt.Println(env[\"KEY_1\"])\n}\n``\n```\n\nfor more details check [go doc](https://pkg.go.dev/pkg/github.com/yassinebenaid/dotenv)\n\n# Contributing\n\nContributions are welcome, make sure to include tests or update exising ones to cover your changes.\n\n_code changes without tests and references to peer dotenv implementations will not be accepted_\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# Licence\n\nCheck the [Licence file](./LICENCE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinebenaid%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyassinebenaid%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinebenaid%2Fdotenv/lists"}