flonfig

package module
v0.0.0-...-c085f52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2018 License: MIT Imports: 6 Imported by: 0

README

Flonfig

Turn your config into flags easily.

Build Status Coverage Status GoDoc Go Report Card

Dependencies

  • go get github.com/BurntSushi/toml

What

Just like what the subtitle says, it is created so you (well, me actually) could turn a config file into flags automatically. You can also add environment variable lookup to the config and flonfig will prioritize the value it got from there. Supported types are:

  • string
  • int
  • int64
  • uint
  • uint64
  • float64
  • duration
  • duration_string (like 3h or 20s)

Why

Because I want a flexible config flag and I don't want to define the flags hardcoded. Essentially, because I am a lazy bum.

How

Just open the examples directory.

TODO

  • Test extracting from env
  • Test real flag values

Notes

Also, I would gladly accept PR.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag struct {
	Key          string      `toml:"key"`
	Env          string      `toml:"env,omitempty"`
	Message      string      `toml:"message"`
	ValueType    string      `toml:"value_type"`
	DefaultValue interface{} `toml:"default_value"`
	ParsedValue  interface{} `toml:"-"`
}

Flag is used to unmarshal the JSON

type Flags

type Flags struct {
	Flags []*Flag `toml:"flags"`
}

Flags is only used to parse the toml

type Flonfig

type Flonfig struct {
	Flags      map[string]*Flag
	ConfigPath string
}

Flonfig is the core of this package

func New

func New() *Flonfig

New will return an empty Flonfig struct pointer

func (*Flonfig) ImplementData

func (f *Flonfig) ImplementData(data string) (err error)

func (*Flonfig) ImplementFile

func (f *Flonfig) ImplementFile(configpathOrData string) (err error)

Implement will load the config file if the target file exists or read it as config string if the target file does not exist and implement it as flags

func (*Flonfig) Parse

func (f *Flonfig) Parse(flags Flags) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL