{"id":26535026,"url":"https://github.com/mikayelgr/hydra","last_synced_at":"2025-03-21T20:30:34.008Z","repository":{"id":42124032,"uuid":"479833657","full_name":"mikayelgr/hydra","owner":"mikayelgr","description":"Hydra is a hybrid configuration management library for Go, with focus on simplicity and testability.","archived":false,"fork":false,"pushed_at":"2022-05-14T05:57:23.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-19T23:35:00.286Z","etag":null,"topics":["configuration","configuration-management","environment","environment-variables","go","golang","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikayelgr.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-04-09T20:13:55.000Z","updated_at":"2022-11-29T18:50:10.000Z","dependencies_parsed_at":"2022-08-12T07:11:35.593Z","dependency_job_id":null,"html_url":"https://github.com/mikayelgr/hydra","commit_stats":null,"previous_names":["getpolygon/hydra","mikayelgr/hydra"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikayelgr%2Fhydra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikayelgr%2Fhydra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikayelgr%2Fhydra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikayelgr%2Fhydra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikayelgr","download_url":"https://codeload.github.com/mikayelgr/hydra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244864971,"owners_count":20523266,"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","configuration-management","environment","environment-variables","go","golang","yaml"],"created_at":"2025-03-21T20:30:33.287Z","updated_at":"2025-03-21T20:30:33.926Z","avatar_url":"https://github.com/mikayelgr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hydra\n\n[![Go CI](https://github.com/getpolygon/hydra/actions/workflows/go.yml/badge.svg)](https://github.com/getpolygon/hydra/actions/workflows/go.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/getpolygon/hydra.svg)](https://pkg.go.dev/github.com/getpolygon/hydra)\n\nHydra is a hybrid configuration management library for Go, created for simplicity and testability. It supports using YAML and optionally paired with environment variables.\n\n## Why?\n\nIn testing environments, you might not want to have separate configuration files for each one of your tests. Moreover, when using more mature configuration libraries such as [Viper](https://github.com/spf13/viper), it is virtually impossible to write tests which use configuration files, since they have to be in a directory different than your project root, which honestly, makes stuff messy.\n\nFor this reason, we created Hydra, which will read, load, and fill in the blanks of the incomplete YAML configuration using environment variables. Think of it this way, if a YAML file does not exist, then Hydra will attempt to load the configuration using environment variables, optionally defined in your schema. However, if a configuration file was found, but has missing fields, Hydra will optionally fill in those fields with the values loaded from the environment.\n\n## Installation\n\nGet started by installing the latest version of hydra:\n\n```bash\ngo get -u github.com/getpolygon/hydra\n```\n\nDefine a configuration schema with validators and names for fallback environment variables:\n\n```go\ntype Settings struct {\n    Port        int16  `yaml:\"port\" env:\"PORT\"`\n    Address     string `yaml:\"address\" env:\"ADDRESS\"`\n    PostgreSQL  string `yaml:\"postgres\" validate:\"uri\" env:\"DSN\"`\n}\n```\n\ncreate the configuration file:\n\n`conf.yml`\n\n```yml\nport: 1234\naddress : \"127.0.0.1\"\npostgres: \"postgres://\u003cpostgres\u003e:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e/\u003cdatabase\u003e?sslmode=disable\"\n```\n\nand load the configuration by creating a `hydra.Hydra` instance:\n\n```go\nh := hydra.Hydra{\n    Config: hydra.Config{\n        Paths: []string{\n            \"~/somepath/config.yaml\",\n        },\n    }\n}\n\n_, err := h.Load(new(Settings))\n// ...\n```\n\nInitially, Hydra will attempt to find an existing configuration file provided from the paths in Hydra configuration, and then it will move on to filling in the missing values from environment variables.\n\n## License\n\nThis software is licensed under the permissive [BSD-3-Clause license](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikayelgr%2Fhydra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikayelgr%2Fhydra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikayelgr%2Fhydra/lists"}