JSON or YAML configuration wrapper with convenient access methods.

Config wercker status GoDoc

Package config provides convenient access methods to configuration stored as JSON or YAML.

This is a fork of the original version. This version extends the functionality of the original without losing compatibility. Major features added:

Example and more information you can find here.

Owner
Oleg Lebedev
Don’t let the Canva bugs bite
Oleg Lebedev
Comments
  • EnvConfig wrapper

    EnvConfig wrapper

    Added EnvConfig wrapper for convenient access to environment settings with fallback to default settings. Also added some tests.

    If the config key exists within the environment, it will be returned. Otherwise, the root is checked for the same key.

    Usage:

    Config:

    val: 22
    defaultVal: "default"
    production:
      val: 333
      strVal: "xx"
    
    envConfig := &EnvConfig{Env: "production", Config: cfg} 
    envConfig.UInt("val") // returns 333, not 22
    envConfig.UString("strVal") // returns "xx"
    envConfig.UString("defaultVal")  // returns "default"
    

    All accessors (string, int, float64, list, map) are duplicated on EnvConfig.

  • RenderYaml|Json adding spurious root

    RenderYaml|Json adding spurious root

    If you load a YAML|JSON with the ParsexxxxFile and then re-write a spurious entitiy of 'root' is added to the YAML|JSON.

    This means that if you then subsequently reload the saved file it will have the spurious root, and most likely will then add another root which is pretty nasty.

  • Set() does not work

    Set() does not work

    .Set() does not seem to actually work.

    cfg.Set("testVal", "test")
    x := cfg.UString("testVal", "")
    // X is ""!
    
  • Add EnvPrefix()

    Add EnvPrefix()

    Same functionality as Env() except a prefix is used when looking up environment variables to replace with. So a key that is looked up with Env() as FOO_BAR will be BAZ_FOO_BAR if EnvPrefix("baz") is used.

    Also updated TestEnv to ensure that the previously set value is overwritten by the environment variable.

    I needed this functionality to avoid environment variables clashing, thanks for the useful library 👍

  • Suggestion - List and StringList

    Suggestion - List and StringList

    Hi, Would you think a StringList is useful on its own besides List? from my uses, it is very common to have a list of strings in configuration rather than list of interface{}

    I'd love to hear your opinion on it Thanks!

  • Fix lists being lost when extending #22

    Fix lists being lost when extending #22

    This PR contains a new implementation of the Extend function. It makes it possible for lists to be extended as well.

    If this PR is merged it will somewhat change the behavior of the function. There are no more errors if the Config structs have a different structure. Look at the description above the implementation for a better overview.

  • func List()

    func List()

    1st, thx 4 giving the great go lib! and i have a question in my dev programs: func List() return a []interface{} for us , but how can i use the var(type []interface) as type []string? hope ur responed

  • [#15] add support for keys with dots

    [#15] add support for keys with dots

    When necessary get key with dots inside, you can use square brackets for example: yaml

    root:
      field.with.dots: value
    

    you can get value like this:

      config.UString("root.[field.with.dots]")
    
  • Godoc examples fail to work on Go 1.9.2

    Godoc examples fail to work on Go 1.9.2

    The following YAML file:

    development:
      database:
        host: localhost
      users:
        - name: calvin
          password: yukon
        - name: hobbes
          password: tuna
    production:
      database:
        host: 192.168.1.1
    

    With the following code:

        if cfg, err := config.ParseYaml("config.yml"); err != nil {
            panic(err)
        } else {
            if testValue, err := cfg.Get("development.database.host"); err != nil {
                panic(err)
            } else {
                fmt.Println("test:", testValue)
            }
        }
    

    Fails with the following error: Invalid type at "development": expected []interface{} or map[string]interface{}; got string

    Note that using cfg.Get or cfg.String results in the same error. YAML handling is non-functional with this library as of the latest revision. The code I have used is a slightly modified version of what is demonstrated in package godocs.

  • Issue parsing command line flags

    Issue parsing command line flags

    I've found that when you have a configuration file where a 'm'ap contains a list of maps wich have more than one key/value' the values returned by getKey() are duplicated because of the 'base slice shares its storage array when called recursively and the new keys fit there.

    Hope you find this useful and can get it merged in. Thanks for making this open source.

  • Allow null values in normalizeValue()

    Allow null values in normalizeValue()

    This adds nil to the list of valid simple value types in normalizeValue(). Otherwise the you would get an "Unsupported type" error when parsing yaml/json content.

  • Lists are lost when using Extend

    Lists are lost when using Extend

    When extending a config with a second Config object which contains lists, all elements in lists in the second object, except the first element, are lost.

    I have narrowed it down to the getKeys function, which generates values like [foo bar 0], [foo bar 1], [foo bar 2], etc : when removing the whole case []interface{}: block in this function, extending seems to work perfectly. I have however not done extensive testing...

  • Nested lists

    Nested lists

    Hi,

    What about such a YAML config:

    part1:
    - level1:
     - level2:
       -level3:
           key1: value1
           key2: value2
    

    How to get deeper nested lists? cfg.List("part1.0.0.)

    does not seem to work.

  • Loading the config file into a string

    Loading the config file into a string

    The Documentation ommits how to load the yaml/json file into a string,

    Here's how I did it:

        file, readErr := ioutil.ReadFile("config.yaml")
        if readErr != nil {
            fmt.Println("Could not read config.yaml:", readErr)
            // Maybe exit the program?
        }
        yamlConfig := string(file)
            // parse the file etc
    

    This would be useful to include in the docs. Also putting some of the documentation's example code into the README.md would be great.

Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Dec 29, 2022
Golang library for reading properties from configuration files in JSON and YAML format or from environment variables.

go-config Golang library for reading properties from configuration files in JSON and YAML format or from environment variables. Usage Create config in

Aug 22, 2022
Go-yaml - Yaml parsing Toolkit For Golang

go-yaml 介绍 gopkg.in/yaml.v3 已经是个非常好用的包,但是在实际开发中总有类型转换带来的麻烦,go-yaml只是在它的基础上,简单的一层

Jan 13, 2022
It syncronizes the configuration described in a YAML file against your GitHub Organization

It syncronizes the configuration described in a YAML file against your GitHub Organization. Combined with a CI system, it can be used to implement GitOps for GitHub.

Jul 19, 2021
Library providing routines to merge and validate JSON, YAML and/or TOML files
Library providing routines to merge and validate JSON, YAML and/or TOML files

CONFLATE Library providing routines to merge and validate JSON, YAML, TOML files and/or structs (godoc) Typical use case: Make your application config

Sep 26, 2022
Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Jun 15, 2022
Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

Nov 14, 2022
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP

config A small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. Example func main() {

Dec 11, 2022
YAML support for the Go language.

YAML support for the Go language Introduction The yaml package enables Go programs to comfortably encode and decode YAML values. It was developed with

Jan 8, 2023
A better way to marshal and unmarshal YAML in Golang

YAML marshaling and unmarshaling support for Go Introduction A wrapper around go-yaml designed to enable a better way of handling YAML when marshaling

Jan 4, 2023
create a bootable disk image from Docker image or a yaml config

docker2boot docker2boot creates a bootable disk from either a Docker image or a config yaml file Features status dns Y cloud-init Y network Y ssh TODO

Oct 30, 2022
YAML support for the Go language
YAML support for the Go language

YAML support for the Go language

Dec 31, 2022
Golang config.yaml loader

Description goconfig is a configuration library designed using the following pri

May 31, 2022
SmartYAML - Go package to handle YAML

SmartYAML - Go package to handle YAML The smartyaml is a go package to handle parsed YAML files more confortable. This package is not a parser, it use

Feb 25, 2022
VINYL Inscribes Nettlesome YAML Legibly

VINYL Inscribes Nettlesome YAML Legibly VINYL formats yaml files into a canonical format retaining comments and setting the indentation by default to

Jan 18, 2022
Go-config - Config parser for go that supports environment vars and multiple yaml files

go-multiconfig This package is able to parse yaml config files. It supports gett

Jun 23, 2022
✨Clean and minimalistic environment configuration reader for Golang

Clean Env Minimalistic configuration reader Overview This is a simple configuration reading tool. It just does the following: reads and parses configu

Jan 8, 2023
12 factor configuration as a typesafe struct in as little as two function calls

Config Manage your application config as a typesafe struct in as little as two function calls. type MyConfig struct { DatabaseUrl string `config:"DAT

Dec 13, 2022