Giter Club home page Giter Club logo

hydra's Introduction

hydra

Go CI Go Reference

Hydra is a hybrid configuration management library for Go, created for simplicity and testability. It supports using YAML and optionally paired with environment variables.

Why?

In 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, 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.

For 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.

Installation

Get started by installing the latest version of hydra:

go get -u github.com/getpolygon/hydra

Define a configuration schema with validators and names for fallback environment variables:

type Settings struct {
    Port        int16  `yaml:"port" env:"PORT"`
    Address     string `yaml:"address" env:"ADDRESS"`
    PostgreSQL  string `yaml:"postgres" validate:"uri" env:"DSN"`
}

create the configuration file:

conf.yml

port: 1234
address : "127.0.0.1"
postgres: "postgres://<postgres>:<password>@<host>:<port>/<database>?sslmode=disable"

and load the configuration by creating a hydra.Hydra instance:

h := hydra.Hydra{
    Config: hydra.Config{
        Paths: []string{
            "~/somepath/config.yaml",
        },
    }
}

_, err := h.Load(new(Settings))
// ...

Initially, 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.

License

This software is licensed under the permissive BSD-3-Clause license.

hydra's People

Contributors

michaelgrigoryan25 avatar segfault99 avatar

Stargazers

 avatar  avatar

Forkers

segfault99

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.