dotconfig

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

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

Go to latest
Published: Apr 29, 2017 License: MIT Imports: 6 Imported by: 2

README

dotconfig

Package dotconfig provides an easy way to load/save configuration to the ~/.config/APP_NAME/config.yml file.

GoDoc Go Report Card

Usage

type settings struct {
	Name     string `yaml:"name"`
	Endpoint string `yaml:"endpoint"`
	Token    string `yaml:"token"`
}

ss := settings{}

if err := dotconfig.Load("my-app", &ss); err != nil {
  if err == dotconfig.ErrConfigNotFound {
    ss.Name = "Name"
    ss.Endpoint = "http://google.com"
    ss.Token = "Some token"
    if err := dotconfig.Save("my-app", ss); err != nil {
      panic(err)
    }
  }
}else if err != nil {
  panic(err)
}

fmt.Printf("Hello %v\n", ss.Name)

See the documentation for information.

Licence

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfigNotFound is used when the config cannot be found during the Loading.
	// This can happen if the configuration never got saved.
	ErrConfigNotFound = errors.New("config not found")
)

Functions

func Load

func Load(appName string, v interface{}) error

Load loads the configuration from ~/.config/{appName}/config.yaml and deserialises it to v.

func Save

func Save(appName string, v interface{}) error

Save serializes and saves the v interface into a YAML file at ~/.config/{appName}/config.yml

Types

This section is empty.

Jump to

Keyboard shortcuts

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