{"id":37164677,"url":"https://github.com/ollevche/enviper","last_synced_at":"2026-01-14T19:33:20.147Z","repository":{"id":57649817,"uuid":"446841364","full_name":"ollevche/enviper","owner":"ollevche","description":"Consider environment variables while unmarshaling viper's config","archived":false,"fork":true,"pushed_at":"2022-01-17T16:14:52.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-20T17:53:25.526Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"iamolegga/enviper","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ollevche.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":"2022-01-11T13:52:52.000Z","updated_at":"2022-01-11T13:59:19.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ollevche/enviper","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ollevche/enviper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollevche%2Fenviper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollevche%2Fenviper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollevche%2Fenviper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollevche%2Fenviper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ollevche","download_url":"https://codeload.github.com/ollevche/enviper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollevche%2Fenviper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28432627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2026-01-14T19:33:19.420Z","updated_at":"2026-01-14T19:33:20.140Z","avatar_url":"https://github.com/ollevche.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enviper\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/iamolegga/enviper)](https://pkg.go.dev/github.com/iamolegga/enviper)\n[![Build Status](https://circleci.com/gh/iamolegga/enviper.svg?style=svg)](https://circleci.com/gh/iamolegga/enviper)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/85fb13ce6638226a3732/test_coverage)](https://codeclimate.com/github/iamolegga/enviper/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/85fb13ce6638226a3732/maintainability)](https://codeclimate.com/github/iamolegga/enviper/maintainability)\n[![Go Report Card](https://goreportcard.com/badge/github.com/iamolegga/enviper)](https://goreportcard.com/report/github.com/iamolegga/enviper)\n\nPackage enviper is a helper/wrapper for [viper](http://github.com/spf13/viper) with the same API.\nIt makes it possible to unmarshal config to struct considering environment variables.\n\n## Problem\n\n[Viper](https://github.com/spf13/viper) package doesn't consider environment variables while unmarshaling.\nPlease, see: [188](https://github.com/spf13/viper/issues/188) and [761](https://github.com/spf13/viper/issues/761)\n\n## Solution\n\nJust wrap viper instance and use the same `Unmarshal` method as you did before:\n\n```go\ne := enviper.New(viper.New())\ne.Unmarshal(\u0026config)\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/iamolegga/enviper\"\n\t\"github.com/spf13/viper\"\n)\n\ntype barry struct {\n    Bar int `mapstructure:\"bar\"`\n}\ntype bazzy struct {\n    Baz bool\n}\ntype quxxy struct {\n\tQux string\n}\ntype config struct {\n    Foo      string\n    Barry    barry\n    Barries  map[string]barry\n    Bazzy    bazzy `mapstructure:\",squash\"`\n    Quxxy    *quxxy\n}\n\n// For example this kind of structure can be unmarshaled with next yaml:\n//  Foo: foo\n//  Barry:\n//    bar: 42\n//  Baz: true\n//  Barries: \n//    key1:\n//      Bar: 255\n//    key2:\n//      Bar: 256\n//  Quxxy:\n//    Qux: \"lorem\"\n//\n// And then it could be overriden by next env variables:\n//  FOO=foo\n//  BARRY_BAR=42\n//  BAZ=true\n//  BARRIES_KEY1_BAR=42\n//  QUXXY_QUX=ipsum\n//\n// Or with prefix:\n//  MYAPP_FOO=foo\n//  MYAPP_BARRY_BAR=42\n//  MYAPP_BAZ=true\n//  MYAPP_BARRIES_KEY1_BAR=42\n//  MYAPP_QUXXY_QUX=ipsum\n\nfunc main() {    \n    var c config\n\n    e := enviper.New(viper.New())\n    e.SetEnvPrefix(\"MYAPP\")\n    e.AddConfigPath(\"/my/config/path\")\n    e.SetConfigName(\"config\")\n\n    e.Unmarshal(\u0026c)\n}\n```\n\n## Custom Tag Names\n\nIn case you want to use custom tag name (something different from `mapstructure`), you have to set it explicitly via `WithTagName` function.\nThe wrapper must know custom tag name in order to register all the env vars for viper so you can't just use `DecoderConfigOption`.\n\n## Credits\n\nThanks to\n[krak3n](https://github.com/krak3n) ([issuecomment-399884438](https://github.com/spf13/viper/issues/188#issuecomment-399884438))\nand\n[celian-garcia](https://github.com/celian-garcia) ([issuecomment-626122696](https://github.com/spf13/viper/issues/761#issuecomment-626122696))\nfor inspiring.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follevche%2Fenviper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Follevche%2Fenviper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follevche%2Fenviper/lists"}