{"id":18396846,"url":"https://github.com/bartventer/viperenv","last_synced_at":"2025-04-12T15:07:58.547Z","repository":{"id":200062840,"uuid":"704490602","full_name":"bartventer/viperenv","owner":"bartventer","description":"A simple way to bind environment variables using Viper.","archived":false,"fork":false,"pushed_at":"2024-06-03T08:50:38.000Z","size":58,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-24T10:38:06.020Z","etag":null,"topics":["configuration","environment-variables","go","viper"],"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/bartventer.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":"2023-10-13T11:21:58.000Z","updated_at":"2024-01-13T04:00:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"7c6580d0-da1e-434c-a8a4-6b1967bfa32c","html_url":"https://github.com/bartventer/viperenv","commit_stats":{"total_commits":6,"total_committers":3,"mean_commits":2.0,"dds":"0.33333333333333337","last_synced_commit":"f05262a1c498e4f422329bbdf4f34bb96fda13fa"},"previous_names":["bartventer/viperenv"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fviperenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fviperenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fviperenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fviperenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartventer","download_url":"https://codeload.github.com/bartventer/viperenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239080898,"owners_count":19578230,"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","viper"],"created_at":"2024-11-06T02:15:01.527Z","updated_at":"2025-02-16T02:32:22.718Z","avatar_url":"https://github.com/bartventer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# viperenv\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/viperenv.svg)](https://pkg.go.dev/github.com/bartventer/viperenv/v2)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bartventer/viperenv)](https://goreportcard.com/report/github.com/bartventer/viperenv)\n[![Coverage Status](https://coveralls.io/repos/github/bartventer/viperenv/badge.svg?branch=master)](https://coveralls.io/github/bartventer/viperenv?branch=master)\n[![Build](https://github.com/bartventer/viperenv/actions/workflows/go.yml/badge.svg)](https://github.com/bartventer/viperenv/actions/workflows/go.yml)\n[![License](https://img.shields.io/github/license/bartventer/viperenv.svg)](LICENSE)\n\n`viperenv` is a Go package that provides a simple way to bind environment variables to a struct using [Viper](https://github.com/spf13/viper). It allows you to define a struct with tags that specify the environment variable names. You can then use the `viperenv.Bind()` function to bind the environment variables to the struct. The upside of this is that you don't have to manually set each environment variable with `viper.BindEnv()`, you can just bind them all at once.\n\n## Installation\n\nTo install `viperenv`, use `go get`:\n\n```sh\ngo get github.com/bartventer/viperenv/v2\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/spf13/viper\"\n    \"github.com/bartventer/viperenv/v2\"\n)\n\ntype Config struct {\n    Host string `env:\"HOST,default=localhost\" mapstructure:\"host\"`\n    Port int    `env:\"PORT\" mapstructure:\"port\"`\n}\n\nfunc main() {\n    // Set environment variables\n    os.Setenv(\"PORT\", \"8080\")\n\n    // Set up viper\n    v := viper.New()\n    var config Config\n    # ... set up viper, and read config file, etc.\n    err := viperenv.Bind(\u0026config, v, viperenv.BindOptions{\n        AutoEnv: true,\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    fmt.Println(config.Host) // \"localhost\"\n    fmt.Println(config.Port) // \"8080\"\n}\n\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fviperenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartventer%2Fviperenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fviperenv/lists"}