All Projects → timestee → goconf

timestee / goconf

Licence: Unlicense License
Configuration loader in Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to goconf

rubric
Linter Config Initializer for Python
Stars: ✭ 21 (-8.7%)
Mutual labels:  config, toml, configuration-files
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-13.04%)
Mutual labels:  config, toml, configuration-files
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+273.91%)
Mutual labels:  config, toml, configuration-files
DazzleConf
Incredible configuration library
Stars: ✭ 34 (+47.83%)
Mutual labels:  config, configuration-files
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+878.26%)
Mutual labels:  config, toml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+878.26%)
Mutual labels:  config, toml
To.ml
OCaml library for TOML
Stars: ✭ 68 (+195.65%)
Mutual labels:  config, toml
tomli
A lil' TOML parser
Stars: ✭ 313 (+1260.87%)
Mutual labels:  config, toml
nvim-config
My neovim config
Stars: ✭ 63 (+173.91%)
Mutual labels:  config, configuration-files
kerrigan
基于Tornado实现的一套配置中心,可基于分项目、环境管理配置,语法高亮、对比历史版本、快速回滚等,并提供Restful风格的API
Stars: ✭ 57 (+147.83%)
Mutual labels:  config, configuration-files
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-21.74%)
Mutual labels:  config, toml
transfer
Converts from one encoding to another. Supported formats HCL ⇄ JSON ⇄ YAML⇄TOML⇄XML⇄plist⇄pickle⇄properties ...
Stars: ✭ 70 (+204.35%)
Mutual labels:  config, toml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+617.39%)
Mutual labels:  config, toml
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+9743.48%)
Mutual labels:  config, flag
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+239.13%)
Mutual labels:  config, toml
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (-8.7%)
Mutual labels:  toml, configuration-files
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+3878.26%)
Mutual labels:  config, toml
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (+21.74%)
Mutual labels:  config, toml
i3
Archivos de configuraciones de i3
Stars: ✭ 32 (+39.13%)
Mutual labels:  config, configuration-files
tomlj
A Java parser for Tom's Obvious, Minimal Language (TOML).
Stars: ✭ 72 (+213.04%)
Mutual labels:  config, toml

[Archived] This repository has been archived,See https://github.com/sandwich-go/xconf instead.

goconf 

Build Status Go Walker GoDoc Go Report CardSourcegraph

Overview

  • Read configuration automatically based on the given struct's field name.
  • Load configuration from multiple sources
  • file inherit

Values are resolved with the following priorities (lowest to highest):

  1. Options struct default value
  2. Flags default value
  3. Config file value, TOML or JSON file
  4. OS Env
  5. Command line flag

About field tags in structs

type TestOptions struct {
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
}
  • flag is the name passed from the command line.
  • cfg is the name used in config files.
  • default is the default value

If do not define flag tag, flag will be snake case of the fild name.

If do not define cfg tag, cfg value will be flag value.

For example, flag and cfg will be http_address.

  HTTPAddress string

Usage

load multiple config files

package main

import "github.com/timestee/goconf"

type TestOptions struct {
    goconf.AutoOptions
    HTTPAddress string `default:"0.0.0.0:0000"`
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
    LogLevel int `default:"3"`
    BoolVar bool `default:"false"`
}

func main() {
   ops := &TestOptions{}
   goconf.MustResolve(ops,"conf_1.toml","conf_2.toml")
}

go run main.go --log_level=1

The output will be:

[Config] auto flag succ, name: _auto_conf_files_ val:
[Config] auto flag succ, name: http_address val: 0.0.0.0:0000
[Config] auto flag fail, name: hosts val: 127.0.0.0,127.0.0.1 err: type not support []string
[Config] auto flag succ, name: log_level val: 3
[Config] auto flag succ, name: bool_var val: false
[Config] file: [conf_1.toml conf_2.toml]
[Config] load: conf_1.toml
[Config] load: conf_2.toml
[Config]
{
   "AutoConfFiles": "",
   "HTTPAddress": "127.0.0.1:2",
   "Hosts": [
      "10.0.61.29",
      "10.0.61.30",
      "10.0.61.31",
      "10.0.61.32"
   ],
   "LogLevel": 1,
   "BoolVar": true
}

load config file with file inherited

package main

import "github.com/timestee/goconf"

type TestOptions struct {
    goconf.AutoOptions
    HTTPAddress string `default:"0.0.0.0:0000"`
    Hosts []string `flag:"hosts" cfg:"hosts" default:"127.0.0.0,127.0.0.1"`
    LogLevel int `default:"3"`
    BoolVar bool `default:"false"`
}

func main() {
   ops := &TestOptions{}
   // conf_3 inherit from conf_1 and conf_2
   goconf.MustResolve(ops,"conf_3.toml")
}

go run main.go --http_address=0.0.0.0:1111111

The output will be:

[Config] auto flag succ, name: _auto_conf_files_ val:
[Config] auto flag succ, name: http_address val: 0.0.0.0:0000
[Config] auto flag fail, name: hosts val: 127.0.0.0,127.0.0.1 err: type not support []string
[Config] auto flag succ, name: log_level val: 3
[Config] auto flag succ, name: bool_var val: false
[Config] file: [conf_3.toml]
[Config] load: ./conf_1.toml
[Config] load: ./conf_2.toml
[Config] load: conf_3.toml
[Config]
{
   "AutoConfFiles": "",
   "HTTPAddress": "0.0.0.0:1111111",
   "Hosts": [
      "10.0.61.29",
      "10.0.61.30",
      "10.0.61.31",
      "10.0.61.32",
      "10.0.61.33"
   ],
   "LogLevel": 2,
   "BoolVar": true
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].