[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5043":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},5043,"godotenv","joho\u002Fgodotenv","joho","A Go port of Ruby's dotenv library (Loads environment variables from .env files)","http:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Fjoho\u002Fgodotenv",null,"Go",10471,451,42,49,0,3,22,63,16,91.27,"MIT License",false,"main",[26,27,28,29],"dotenv","environment-variables","go","golang","2026-06-12 04:00:24","# GoDotEnv ![CI](https:\u002F\u002Fgithub.com\u002Fjoho\u002Fgodotenv\u002Fworkflows\u002FCI\u002Fbadge.svg) [![Go Report Card](https:\u002F\u002Fgoreportcard.com\u002Fbadge\u002Fgithub.com\u002Fjoho\u002Fgodotenv)](https:\u002F\u002Fgoreportcard.com\u002Freport\u002Fgithub.com\u002Fjoho\u002Fgodotenv)\n\nA Go (golang) port of the Ruby [dotenv](https:\u002F\u002Fgithub.com\u002Fbkeepers\u002Fdotenv) project (which loads env vars from a .env file).\n\nFrom the original Library:\n\n> Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.\n>\n> But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped.\n\nIt can be used as a library (for loading in env for your own daemons etc.) or as a bin command.\n\nThere is test coverage and CI for both linuxish and Windows environments, but I make no guarantees about the bin version working on Windows.\n\n## Installation\n\nAs a library\n\n```shell\ngo get github.com\u002Fjoho\u002Fgodotenv\n```\n\nor if you want to use it as a bin command\n\ngo >= 1.17\n```shell\ngo install github.com\u002Fjoho\u002Fgodotenv\u002Fcmd\u002Fgodotenv@latest\n```\n\ngo \u003C 1.17\n```shell\ngo get github.com\u002Fjoho\u002Fgodotenv\u002Fcmd\u002Fgodotenv\n```\n\n## Usage\n\nAdd your application configuration to your `.env` file in the root of your project:\n\n```shell\nS3_BUCKET=YOURS3BUCKET\nSECRET_KEY=YOURSECRETKEYGOESHERE\n```\n\nThen in your Go app you can do something like\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"os\"\n\n    \"github.com\u002Fjoho\u002Fgodotenv\"\n)\n\nfunc main() {\n  err := godotenv.Load()\n  if err != nil {\n    log.Fatal(\"Error loading .env file\")\n  }\n\n  s3Bucket := os.Getenv(\"S3_BUCKET\")\n  secretKey := os.Getenv(\"SECRET_KEY\")\n\n  \u002F\u002F now do something with s3 or whatever\n}\n```\n\nIf you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import\n\n```go\nimport _ \"github.com\u002Fjoho\u002Fgodotenv\u002Fautoload\"\n```\n\nWhile `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit\n\n```go\ngodotenv.Load(\"somerandomfile\")\ngodotenv.Load(\"filenumberone.env\", \"filenumbertwo.env\")\n```\n\nIf you want to be really fancy with your env file you can do comments and exports (below is a valid env file)\n\n```shell\n# I am a comment and that is OK\nSOME_VAR=someval\nFOO=BAR # comments at line end are OK too\nexport BAR=BAZ\n```\n\nOr finally you can do YAML(ish) style\n\n```yaml\nFOO: bar\nBAR: baz\n```\n\nas a final aside, if you don't want godotenv munging your env you can just get a map back instead\n\n```go\nvar myEnv map[string]string\nmyEnv, err := godotenv.Read()\n\ns3Bucket := myEnv[\"S3_BUCKET\"]\n```\n\n... or from an `io.Reader` instead of a local file\n\n```go\nreader := getRemoteFile()\nmyEnv, err := godotenv.Parse(reader)\n```\n\n... or from a `string` if you so desire\n\n```go\ncontent := getRemoteFileContent()\nmyEnv, err := godotenv.Unmarshal(content)\n```\n\n### Precedence & Conventions\n\nExisting envs take precedence of envs that are loaded later.\n\nThe [convention](https:\u002F\u002Fgithub.com\u002Fbkeepers\u002Fdotenv#what-other-env-files-can-i-use)\nfor managing multiple environments (i.e. development, test, production)\nis to create an env named `{YOURAPP}_ENV` and load envs in this order:\n\n```go\nenv := os.Getenv(\"FOO_ENV\")\nif \"\" == env {\n  env = \"development\"\n}\n\ngodotenv.Load(\".env.\" + env + \".local\")\nif \"test\" != env {\n  godotenv.Load(\".env.local\")\n}\ngodotenv.Load(\".env.\" + env)\ngodotenv.Load() \u002F\u002F The Original .env\n```\n\nIf you need to, you can also use `godotenv.Overload()` to defy this convention\nand overwrite existing envs instead of only supplanting them. Use with caution.\n\n### Command Mode\n\nAssuming you've installed the command as above and you've got `$GOPATH\u002Fbin` in your `$PATH`\n\n```\ngodotenv -f \u002Fsome\u002Fpath\u002Fto\u002F.env some_command with some args\n```\n\nIf you don't specify `-f` it will fall back on the default of loading `.env` in `PWD`\n\nBy default, it won't override existing environment variables; you can do that with the `-o` flag.\n\n### Writing Env Files\n\nGodotenv can also write a map representing the environment to a correctly-formatted and escaped file\n\n```go\nenv, err := godotenv.Unmarshal(\"KEY=value\")\nerr := godotenv.Write(env, \".\u002F.env\")\n```\n\n... or to a string\n\n```go\nenv, err := godotenv.Unmarshal(\"KEY=value\")\ncontent, err := godotenv.Marshal(env)\n```\n\n## Contributing\n\nContributions are welcome, but with some caveats.\n\nThis library has been declared feature complete (see [#182](https:\u002F\u002Fgithub.com\u002Fjoho\u002Fgodotenv\u002Fissues\u002F182) for background) and will not be accepting issues or pull requests adding new functionality or breaking the library API.\n\nContributions would be gladly accepted that:\n\n* bring this library's parsing into closer compatibility with the mainline dotenv implementations, in particular [Ruby's dotenv](https:\u002F\u002Fgithub.com\u002Fbkeepers\u002Fdotenv) and [Node.js' dotenv](https:\u002F\u002Fgithub.com\u002Fmotdotla\u002Fdotenv)\n* keep the library up to date with the go ecosystem (ie CI bumps, documentation changes, changes in the core libraries)\n* bug fixes for use cases that pertain to the library's purpose of easing development of codebases deployed into twelve factor environments\n\n*code changes without tests and references to peer dotenv implementations will not be accepted*\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Releases\n\nReleases should follow [Semver](http:\u002F\u002Fsemver.org\u002F) though the first couple of releases are `v1` and `v1.1`.\n\nUse [annotated tags for all releases](https:\u002F\u002Fgithub.com\u002Fjoho\u002Fgodotenv\u002Fissues\u002F30). Example `git tag -a v1.2.1`\n\n## Who?\n\nThe original library [dotenv](https:\u002F\u002Fgithub.com\u002Fbkeepers\u002Fdotenv) was written by [Brandon Keepers](http:\u002F\u002Fopensoul.org\u002F), and this port was done by [John Barton](https:\u002F\u002Fjohnbarton.co\u002F) based off the tests\u002Ffixtures in the original library.\n","joho\u002Fgodotenv 是一个用 Go 语言实现的从 .env 文件加载环境变量的库，灵感来源于 Ruby 的 dotenv 库。其核心功能包括从 .env 文件中读取环境变量并将其载入到运行时环境中，支持多文件加载、注释和导出语法，以及 YAML 格式的解析。此外，它还提供了自动加载机制，并允许用户选择将环境变量直接作为 map 返回而非修改当前进程的环境变量。此项目适用于需要在开发或测试环境中通过配置文件管理可变参数的 Go 语言应用程序，尤其适合遵循十二因素应用原则的应用场景。",2,"2026-06-11 03:02:14","top_language"]