{"id":13410934,"url":"https://github.com/sakirsensoy/genv","last_synced_at":"2025-03-14T16:33:21.542Z","repository":{"id":57496784,"uuid":"196976882","full_name":"sakirsensoy/genv","owner":"sakirsensoy","description":"Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.","archived":false,"fork":false,"pushed_at":"2019-07-27T11:56:32.000Z","size":27,"stargazers_count":37,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T20:44:28.996Z","etag":null,"topics":["configuration","dotenv","environment","environment-variables","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/sakirsensoy.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}},"created_at":"2019-07-15T10:25:57.000Z","updated_at":"2024-07-30T11:54:18.000Z","dependencies_parsed_at":"2022-09-03T02:10:33.478Z","dependency_job_id":null,"html_url":"https://github.com/sakirsensoy/genv","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakirsensoy%2Fgenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakirsensoy%2Fgenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakirsensoy%2Fgenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakirsensoy%2Fgenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakirsensoy","download_url":"https://codeload.github.com/sakirsensoy/genv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221486919,"owners_count":16830966,"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","dotenv","environment","environment-variables","golang"],"created_at":"2024-07-30T20:01:10.314Z","updated_at":"2025-03-14T16:33:21.496Z","avatar_url":"https://github.com/sakirsensoy.png","language":"Go","funding_links":[],"categories":["配置管理","配置","Configuration","配置管理 `配置解析库`","Uncategorized"],"sub_categories":["标准 CLI","标准CLI","Standard CLI","Advanced Console UIs"],"readme":"# genv\n\n[![GitHub Actions](https://github.com/sakirsensoy/genv/actions/workflows/go.yml/badge.svg)](https://github.com/sakirsensoy/genv/actions/workflows/go.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/sakirsensoy/genv)](https://goreportcard.com/report/github.com/sakirsensoy/genv) [![Coverage Status](https://coveralls.io/repos/github/sakirsensoy/genv/badge.svg?branch=master)](https://coveralls.io/github/sakirsensoy/genv?branch=master) [![GoDoc](https://godoc.org/github.com/sakirsensoy/genv?status.svg)](https://godoc.org/github.com/sakirsensoy/genv)\n\nGenv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.\n\n## Installation\n\n```shell\ngo get github.com/sakirsensoy/genv\n```\n\n## Usage\n\nCreate a `.env` file in the root directory of your project and enter the environment variables you want to use:\n\n```shell\n# .env\nAPP_HOST=localhost\nAPP_PORT=1234\nAPP_DEBUG=true\n```\n\nIn the meantime, it is optional to use the `.env` file. You can also send environment variables to your project in classic ways:\n\n```shell\nAPP_HOST=localhost ./myproject\n```\n\nRather than using your environment variables directly in your project, it is better to map and match them with a struct.  Below you can see how we get our application parameters from environment variables:\n\n```go\n// config/config.go\npackage config\n\nimport \"github.com/sakirsensoy/genv\"\n\ntype appConfig struct {\n\tHost string\n\tPort int\n\tDebug bool\n}\n\nvar  App = \u0026appConfig{\n\tHost: genv.Key(\"APP_HOST\").String(),\n\tPort: genv.Key(\"APP_PORT\").Default(8080).Int(),\n\tDebug: genv.Key(\"APP_DEBUG\").Default(false).Bool(),\n}\n```\n\nIn `main.go` we first include the package that allows you to automatically load the environment variables from the .env file. Then we can include and use the parameters defined in `config.go`:\n\n```go\n// main.go\npackage main\n\nimport (\n\t_ \"github.com/sakirsensoy/genv/dotenv/autoload\"\n\n\t\"fmt\"\n\t\"myproject/config\"\n)\n\nfunc  main() {\n\tfmt.Println(config.App.Host) // localhost\n\tfmt.Println(config.App.Port) // 1234\n\tfmt.Println(config.App.Debug) // true\n}\n```\n\n### Accessing Environment Variables\n\nGenv provides an easy-to-use API for accessing environment variables.\n\n\u003e First we specify the key to the variable want to access\n\n```go\nvar env = genv.Key(\"MY_VARIABLE\")\n```\n\n\u003e Define default value (optional)\n\n```go\nenv = env.Default(\"default_value\")\n```\n\n\u003e Finally, we specify the type of the environment variable and pass its contents to another variable\n\n```go\nvar myVariable = env.String()\n```\n\n### Supported Variable Types\n\nGenv provides support for the following data types:\n\n - `String()`: Returns data of **String** type\n - `Int()`: Returns data of **Int32** type\n - `Float()`: Returns data of **Float64** type\n - `Bool()`: Returns data of **Bool** type\n\nFor other types, you can use type conversion:\n\n```go\nvar stringValue = genv.Key(\"KEY\").String()\nvar byteArrayValue = []byte(stringValue)\n```\n\n## Contributing\n\nThanks in advance for your contributions :) I would appreciate it if you make sure that the API remains simple when developing.\n\n*code changes without tests 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## License\n\n© Şakir Şensoy, 2019 ~ time.Now()\n\nReleased under the [MIT License](https://github.com/sakirsensoy/genv/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakirsensoy%2Fgenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakirsensoy%2Fgenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakirsensoy%2Fgenv/lists"}