Git Product home page Git Product logo

alligotor's Introduction

Alligotor

golangci-lint Go Report Card Go Reference

The zero configuration configuration package.

Install

go get github.com/brumhard/alligotor

What is Alligotor?

Alligotor is designed to be used as the configuration source for executables (not commands in a command line application) for example for apis or any other long running application that need a startup config.

It takes only a few lines of code to get going, and it supports:

  • setting defaults just like you're used to from for example json unmarshalling (see this example)
  • reading from YAML and JSON files
  • reading from environment variables
  • reading from command line flags
  • disabling sources
  • extremely simple API
  • support for every type (by implementing TextUnmarshaler) and out of the box support for many common ones
  • setting paths in each configuration source for default values (see the example)

Why Alligotor?

There are a lot of configuration packages for Go that give you the ability to load you configuration from several sources like env vars, command line flags or config files.

Alligotor was designed to have the least configuration effort possible while still keeping it customizable. That's why if you keep the package defaults you only need one function call and your config struct definition to fill this struct with values from environment variables, several config files and also command line flags.

Also default can default paths can be used to keep your configuration as small as possible. Default paths means that you set a name/path in the configuration source from which multiple fields take their value if they're not set in any other way. See this example for further information.

Minimal example

package main

import (

"github.com/brumhard/alligotor"
"go.uber.org/zap/zapcore"
"time"
)

func main() {
    // define the config struct
    cfg := struct{
        SomeList []string
        SomeMap  map[string]string
        API      struct {
            Enabled  bool
            LogLevel zapcore.Level
        }
        DB struct {
            HostName string
            Timeout  time.Duration
        }
    }{
        // could define defaults here
    }
    
    // get the values
    _ = alligotor.Get(&cfg)
}

TODO

  • Description for fields either in struct tags or in json schema
  • Support for other file formats
  • Benchmark against viper and other configuration packages for cold start scenarios

alligotor's People

Contributors

brumhard avatar

Watchers

 avatar

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.