All Projects → traefik → paerser

traefik / paerser

Licence: Apache-2.0 license
No description or website provided.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to paerser

Fig
A minimalist Go configuration library
Stars: ✭ 142 (+273.68%)
Mutual labels:  yaml, toml, configuration, environment-variables
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 (+126.32%)
Mutual labels:  yaml, toml, configuration, environment-variables
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-47.37%)
Mutual labels:  yaml, toml, configuration, environment-variables
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+334.21%)
Mutual labels:  yaml, toml, configuration
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (+144.74%)
Mutual labels:  yaml, toml, configuration
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+105.26%)
Mutual labels:  yaml, toml, configuration
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-52.63%)
Mutual labels:  yaml, toml, configuration
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+492.11%)
Mutual labels:  yaml, toml, configuration
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+5378.95%)
Mutual labels:  yaml, configuration, environment-variables
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (+1084.21%)
Mutual labels:  yaml, toml, configuration
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+1897.37%)
Mutual labels:  yaml, toml, configuration
go-config
Configuration file loader for Go
Stars: ✭ 27 (-28.95%)
Mutual labels:  yaml, toml, configuration
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (-44.74%)
Mutual labels:  yaml, toml, environment-variables
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+110.53%)
Mutual labels:  yaml, configuration, environment-variables
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-26.32%)
Mutual labels:  yaml, toml, environment-variables
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (+26.32%)
Mutual labels:  yaml, toml, configuration
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (+197.37%)
Mutual labels:  yaml, toml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+4657.89%)
Mutual labels:  yaml, toml
Configurate
A simple configuration library for Java applications providing a node structure, a variety of formats, and tools for transformation
Stars: ✭ 148 (+289.47%)
Mutual labels:  yaml, configuration
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 (+492.11%)
Mutual labels:  yaml, toml

Paerser

Package documentation Build Status Go Report Card

Features

Loads configuration from many sources:

  • CLI flags
  • Configuration files in YAML, TOML, JSON format
  • Environment variables

It also provides a simple CLI commands handling system.

Examples

Configuration

CLI Flags

package flag_test

import (
	"log"

	"github.com/davecgh/go-spew/spew"
	"github.com/traefik/paerser/flag"
)

type ConfigExample struct {
	Foo   string
	Bar   Bar
	Great bool
}

type Bar struct {
	Sub  *Sub
	List []string
}

type Sub struct {
	Name  string
	Value int
}

func ExampleDecode() {
	args := []string{
		"--foo=aaa",
		"--great=true",
		"--bar.list=AAA,BBB",
		"--bar.sub.name=bbb",
		"--bar.sub.value=6",
	}

	config := ConfigExample{}

	err := flag.Decode(args, &config)
	if err != nil {
		log.Fatal(err)
	}

	spew.Config = spew.ConfigState{
		Indent:                  "\t",
		DisablePointerAddresses: true,
	}
	spew.Dump(config)

	// Output:
	// (flag_test.ConfigExample) {
	// 	Foo: (string) (len=3) "aaa",
	// 	Bar: (flag_test.Bar) {
	// 		Sub: (*flag_test.Sub)({
	// 			Name: (string) (len=3) "bbb",
	// 			Value: (int) 6
	// 		}),
	// 		List: ([]string) (len=2 cap=2) {
	// 			(string) (len=3) "AAA",
	// 			(string) (len=3) "BBB"
	// 		}
	// 	},
	// 	Great: (bool) true
	// }
}

File

package file_test

import (
	"fmt"
	"log"
	"os"

	"github.com/davecgh/go-spew/spew"
	"github.com/traefik/paerser/file"
)

type ConfigExample struct {
	Foo   string
	Bar   Bar
	Great bool
}

type Bar struct {
	Sub  *Sub
	List []string
}

type Sub struct {
	Name  string
	Value int
}

func ExampleDecode() {
	tempFile, err := os.CreateTemp("", "paeser-*.yml")
	if err != nil {
		log.Fatal(err)
	}

	defer func() { _ = os.RemoveAll(tempFile.Name()) }()

	data := `
foo: aaa
bar:
  sub:
    name: bbb
    value: 6
  list:
  - AAA
  - BBB
great: true
`

	_, err = fmt.Fprint(tempFile, data)
	if err != nil {
		log.Fatal(err)
	}

	// Read configuration file

	filePath := tempFile.Name()

	config := ConfigExample{}

	err = file.Decode(filePath, &config)
	if err != nil {
		log.Fatal(err)
	}

	spew.Config = spew.ConfigState{
		Indent:                  "\t",
		DisablePointerAddresses: true,
	}
	spew.Dump(config)

	// Output:
	// (file_test.ConfigExample) {
	// 	Foo: (string) (len=3) "aaa",
	// 	Bar: (file_test.Bar) {
	// 		Sub: (*file_test.Sub)({
	// 			Name: (string) (len=3) "bbb",
	// 			Value: (int) 6
	// 		}),
	// 		List: ([]string) (len=2 cap=2) {
	// 			(string) (len=3) "AAA",
	// 			(string) (len=3) "BBB"
	// 		}
	// 	},
	// 	Great: (bool) true
	// }
}

Environment Variables

package env_test

import (
	"log"
	"os"

	"github.com/davecgh/go-spew/spew"
	"github.com/traefik/paerser/env"
)

type ConfigExample struct {
	Foo   string
	Bar   Bar
	Great bool
}

type Bar struct {
	Sub  *Sub
	List []string
}

type Sub struct {
	Name  string
	Value int
}

func ExampleDecode() {
	_ = os.Setenv("MYAPP_FOO", "aaa")
	_ = os.Setenv("MYAPP_GREAT", "true")
	_ = os.Setenv("MYAPP_BAR_LIST", "AAA,BBB")
	_ = os.Setenv("MYAPP_BAR_SUB_NAME", "bbb")
	_ = os.Setenv("MYAPP_BAR_SUB_VALUE", "6")

	config := ConfigExample{}

	err := env.Decode(os.Environ(), "MYAPP_", &config)
	if err != nil {
		log.Fatal(err)
	}

	spew.Config = spew.ConfigState{
		Indent:                  "\t",
		DisablePointerAddresses: true,
	}
	spew.Dump(config)

	// Output:
	// (env_test.ConfigExample) {
	// 	Foo: (string) (len=3) "aaa",
	// 	Bar: (env_test.Bar) {
	// 		Sub: (*env_test.Sub)({
	// 			Name: (string) (len=3) "bbb",
	// 			Value: (int) 6
	// 		}),
	// 		List: ([]string) (len=2 cap=2) {
	// 			(string) (len=3) "AAA",
	// 			(string) (len=3) "BBB"
	// 		}
	// 	},
	// 	Great: (bool) true
	// }
}

CLI Commands

TODO
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].