configure

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: MIT Imports: 11 Imported by: 3

README

go-configure

configure anything more effectively, easily, and speedy!

Description

go-configure is a library which manage config files.

Requirements

Usage

First of all, define the structure for config.

package config 

type Foo struct {
  Hoge string
  Fuga int
}

type Bar struct {
  Piyo string
}

type Config struct {
  Foo *Foo
  Bar *Bar
}

var meta *configure.Configure

func init() {
  // (example) init config if you need it
  conf := Config{
    Foo: &Foo{
      Hoge: "hoge",
      Fuga: "fuga",
    },
    Bar: &Bar{
      Piyo: "piyo",
    },
  }

  // init go-configure
  var err error
  meta, err = configure.NewConfigure("~/.example.config.toml", conf, nil)
}

// You need to use mapstructure to convert map[string]interface{} to the defined type
func Get() *Config {
  var config Config
  mapstructure.Decode(meta.Get(), &config)
  return &config
}

func Edit() error {
  return meta.Edit()
}

Use or edit config

// Get config
config.Get()

// Edit config by editor (Edit() opens the config file by editor)
config.Edit()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configure

type Configure struct {
	// contains filtered or unexported fields
}

func NewConfigure

func NewConfigure(fpath string, config interface{}, opt *Option) (*Configure, error)

func (*Configure) Edit

func (c *Configure) Edit() error

func (*Configure) Get

func (c *Configure) Get() map[string]interface{}

func (*Configure) Init

func (c *Configure) Init() error

func (*Configure) Load

func (c *Configure) Load() error

type NotationType

type NotationType int8
const (
	NotationTypeTOML NotationType = iota
	NotationTypeJSON
	NotationTypeYAML
)

type Option

type Option struct {
	NotationType NotationType
	SyncRealTime bool
	Editor       string
}

Jump to

Keyboard shortcuts

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