{"id":36454551,"url":"https://github.com/rickferrdev/dotenv","last_synced_at":"2026-01-11T23:01:39.082Z","repository":{"id":329296737,"uuid":"1118506530","full_name":"rickferrdev/dotenv","owner":"rickferrdev","description":"A lightweight, zero-dependency Go package for loading environment variables from .env and .env.local files into your application.","archived":false,"fork":false,"pushed_at":"2025-12-27T20:54:36.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-29T21:14:09.525Z","etag":null,"topics":["dotenv-loader","environment","go-package","library","loadenv"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/rickferrdev/dotenv","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rickferrdev.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-17T21:27:58.000Z","updated_at":"2025-12-28T17:57:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rickferrdev/dotenv","commit_stats":null,"previous_names":["rickferrdev/dotenv"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rickferrdev/dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickferrdev%2Fdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickferrdev%2Fdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickferrdev%2Fdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickferrdev%2Fdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rickferrdev","download_url":"https://codeload.github.com/rickferrdev/dotenv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickferrdev%2Fdotenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28326166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T22:11:01.104Z","status":"ssl_error","status_checked_at":"2026-01-11T22:10:58.990Z","response_time":60,"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-loader","environment","go-package","library","loadenv"],"created_at":"2026-01-11T23:01:38.982Z","updated_at":"2026-01-11T23:01:39.068Z","avatar_url":"https://github.com/rickferrdev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotenv\n\nA lightweight, zero-dependency Go package for loading environment variables from `.env` and `.env.local` files, with built-in support for mapping variables directly into Go structs.\n\n## Features\n\n* **File Priority**: Automatically loads `.env` and overrides with `.env.local` if present.\n* **Struct Mapping**: Unmarshal environment variables directly into strict-typed Go structs.\n* **Env Generation**: Marshal structs back into `.env` formatted strings.\n* **Shell Support**: Recognizes the `export` keyword.\n* **Comment Handling**: Ignores lines starting with `#` and strips inline comments.\n* **Smart Quoting**: Automatically handles values wrapped in single (`'`) or double (`\"`) quotes.\n* **Zero Dependencies**: Uses only the Go standard library.\n\n## Installation\n\n```bash\ngo get github.com/rickferrdev/dotenv\n```\n\n## Usage\n\n### 1. Basic Loading (`Collect`)\n\nCreate your environment files:\n\n**`.env`**\n```bash\nPORT=8080\nDB_URL=\"postgres://user:password@localhost:5432/db\"\nDEBUG=true\n```\n\nCall `dotenv.Collect()` as early as possible in your `main` function (or `init`) to populate `os.Environ`.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"os\"\n    \"github.com/rickferrdev/dotenv\"\n)\n\nfunc main() {\n    // 1. Load variables from .env files into system environment\n    dotenv.Collect()\n\n    // 2. Access them normally\n    port := os.Getenv(\"PORT\")\n    fmt.Printf(\"Server starting on port: %s\\n\", port)\n}\n```\n\n### 2. Struct Mapping (`Unmarshal`)\n\nInstead of parsing strings manually, map environment variables directly to a struct using the `env` tag.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"github.com/rickferrdev/dotenv\"\n)\n\ntype Config struct {\n    Port      int     `env:\"PORT\"`\n    DbURL     string  `env:\"DB_URL\"`\n    Debug     bool    `env:\"DEBUG\"`\n    RateLimit float64 `env:\"RATE_LIMIT\"`\n}\n\nfunc main() {\n    dotenv.Collect() // Load files first\n\n    var cfg Config\n\n    // Parse environment variables into the struct\n    if err := dotenv.Unmarshal(\u0026cfg); err != nil {\n        log.Fatalf(\"Could not parse config: %v\", err)\n    }\n\n    fmt.Printf(\"Config loaded: Port %d, Debug %v\\n\", cfg.Port, cfg.Debug)\n}\n```\n\n### 3. Generating .env Content (`Marshal`)\n\nYou can also convert a struct back into a `.env` formatted string.\n\n```go\ncfg := Config{\n    Port:  9090,\n    Debug: false,\n}\n\ndata, err := dotenv.Marshal(\u0026cfg)\nif err != nil {\n    panic(err)\n}\n\nfmt.Println(string(data))\n// Output:\n// PORT=9090\n// DEBUG=false\n// ...\n```\n\n## Configuration\n\nYou can override the files the package looks for by modifying the `FilenameVariables` slice before calling `Collect`.\n\n```go\n// Look for production files instead of default .env\ndotenv.FilenameVariables = []string{\".env.production\", \".env\"}\ndotenv.Collect()\n```\n\n## How it Works\n\n* **`Collect()`**: Iterates through `FilenameVariables`. It parses each line, strips `export` prefixes, handles quotes, cleans comments, and sets values using `os.Setenv`.\n* **`Unmarshal()`**: Uses Go reflection to inspect struct tags (`env:\"KEY\"`) and automatically converts string environment values into the appropriate Go types (`int`, `bool`, `float`, `string`).\n* **`Marshal()`**: Reads the struct values and tags to generate a key-value string suitable for `.env` files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickferrdev%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickferrdev%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickferrdev%2Fdotenv/lists"}