All Projects → distributedio → configo

distributedio / configo

Licence: MIT license
Configo is a go library to parse toml configuration using struct tags

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to configo

go-config
Configuration file loader for Go
Stars: ✭ 27 (-18.18%)
Mutual labels:  toml
Tomlet
Zero-Dependency, model-based TOML De/Serializer for .NET
Stars: ✭ 56 (+69.7%)
Mutual labels:  toml
tomlify-j0.4
An Object->TOML encoder/converter for TOML v0.4.0 (not v0.4.x)
Stars: ✭ 16 (-51.52%)
Mutual labels:  toml
cmkr
Modern build system based on CMake and TOML.
Stars: ✭ 211 (+539.39%)
Mutual labels:  toml
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-39.39%)
Mutual labels:  toml
tomlcpp
No fanfare TOML C++ Library
Stars: ✭ 21 (-36.36%)
Mutual labels:  toml
toml
TOML parser and encoder for Go with reflection.
Stars: ✭ 19 (-42.42%)
Mutual labels:  toml
tomland
🏝 Bidirectional TOML serialization
Stars: ✭ 103 (+212.12%)
Mutual labels:  toml
transfer
Converts from one encoding to another. Supported formats HCL ⇄ JSON ⇄ YAML⇄TOML⇄XML⇄plist⇄pickle⇄properties ...
Stars: ✭ 70 (+112.12%)
Mutual labels:  toml
tomlj
A Java parser for Tom's Obvious, Minimal Language (TOML).
Stars: ✭ 72 (+118.18%)
Mutual labels:  toml
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-45.45%)
Mutual labels:  toml
contentful-export
Extract Contentful to Hugo
Stars: ✭ 22 (-33.33%)
Mutual labels:  toml
audible-cli
A command line interface for audible package. With the cli you can download your Audible books, cover, chapter files.
Stars: ✭ 142 (+330.3%)
Mutual labels:  toml
crates
crates is an extension aims to help people to manage their dependencies for rust (crates.io & TOML).
Stars: ✭ 156 (+372.73%)
Mutual labels:  toml
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 (+160.61%)
Mutual labels:  toml
parsetoml
A Nim library to parse TOML files
Stars: ✭ 96 (+190.91%)
Mutual labels:  toml
front-matter
The most featured front matter (yaml, json, neon, toml) parser and dumper for PHP.
Stars: ✭ 23 (-30.3%)
Mutual labels:  toml
pytomlpp
A python wrapper for tomlplusplus
Stars: ✭ 56 (+69.7%)
Mutual labels:  toml
Molten
[WIP] Molten - Style-preserving TOML parser.
Stars: ✭ 36 (+9.09%)
Mutual labels:  toml
tree-sitter-toml
TOML grammar for tree-sitter
Stars: ✭ 23 (-30.3%)
Mutual labels:  toml

Configo

Configo is a go library to parse toml configuration using struct tags

Features

  • Configuring parser behaviour using struct tags
  • Setting default value or as required
  • Validating value using regex, range expression or named validator
  • Generating toml template with human friendly information based on go struct and tags
  • Building conf file generation tools using configo-build

QuickStart

  • Install configo-build tool for config generation

go get github.com/distributedio/configo/bin/configo-build

  • Define a struct in package conf
package conf

type Config struct {
        Listen  string `cfg:"listen; :8804; netaddr; The address the server to listen"`
        MaxConn int    `cfg:"max-connection; 10000; numeric; Max number of concurrent connections"`
        Redis   struct {
                Cluster []string `cfg:"cluster; required; dialstring; The addresses of redis cluster"`
        }
}
  • Use configo-build tool generate config builder, if everything goes well, you'll get a binary called conf.Config.cfg

configo-build ./conf.Config

or use the absolute path

configo-build github.com/distributedio/configo/example/conf.Config

  • execute builer to generate a toml

conf.config.cfg > conf.toml

or patch you toml file if it is already existed

conf.config.cfg -patch conf.toml

  • Use your config in your code
import "github.com/distributedio/configo"

var conf conf.Config

if err := configo.Parse("{PATH_TO_YOUR_TOML}", &conf) ;err != nil {
// handle the error
}

Toml

shafreeck/toml is a modification version of naoina/toml, adding the abililty to parse complex struct tags and with bugs fixed.

Validation

configo has a builtin validator with regex and range support

Supported named validator

  • netaddr
  • url
  • nonempty
  • dialstring
  • boolean
  • numeric
  • printableascii
  • path

and you can also use compare operator and regExp in tags

> 1 //greater than 1
>=1 //greater than or equal to 1
>1 <10 //greater than 1 and less than 10, space indicates the "and" of rules

(1, ) //range expression, same as >1
(1, 10) // >1 <10
(1,10]  // >1 <=10

/[0-9]/ //regex matching

/[0-9]+/ (1, 10) // the value should satisfy both the regex and range expression

netaddr //named validator, used to validate a network address
numeric  >10 ( ,100)// mix different expressions, 'and' is used to combine all expressions

See the Suppoted Vaildator for all valid "named validators"

Struct tags

tags has a key 'cfg' and its value consists of four parts: "name; default value or required; rule; descripion". All four parts are splited by ";".

For example:

Listen `cfg:"listen; :8804; netaddr; The listen address of server"`

It looks like this when being marshaled to toml

#type:        string
#rules:       netaddr
#description: The listen address of server
#default:     :8804
#listen=":8804"

You can see that we have rich information about the option. And the option is commented out too because it has a default value.

configo-build

Configo comes with a util tool called configo-build to build a configration file generator for you.

You can use the generator to generate your toml file or update it when you changed your source code(the configuration struct).

configo-build ./conf.Config
#build a conf generator, the format of arg is "package.struct" package can be
#absolute or relative(golang takes it as an absolute package if it is without
#the prefix "./" or "../").

#the built program has a name with format:<package>.<struct>.cfg, for example
#"conf.config.cfg"

Generating your configuration file with the built generator

conf.config.cfg > conf.toml #generating
conf.config.cfg -patch conf.toml #updating if conf.toml has already existed
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].