dot

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 8 Imported by: 0

README

go-dot

GoDoc Go Report Card

go-dot is a library to save/load a config structure from dot app folder / file.

Documentation

https://godoc.org/github.com/byounghoonkim/go-dot

Documentation

Overview

Example
type Config struct {
	Server   string
	Username string
}

config := Config{
	"server1",
	"user1",
}

d := dot.New()
err := d.Save(&config)
if err != nil {
	panic(err)
}

configFolder, err := d.GetConfigFolder()
if err != nil {
	panic(err)
}
fmt.Println("config folder : ", configFolder)

configPath, err := d.GetConfigPath(&config)
if err != nil {
	panic(err)
}
fmt.Println("config path   : ", configPath)

config2 := Config{}
err = d.Load(&config2)
if err != nil {
	panic(err)
}

fmt.Printf("%+v", config2)
Output:

Index

Examples

Constants

View Source
const (
	// YAML format
	YAML = ".yml"
	//JSON format
	JSON = ".json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dot

type Dot struct {
	AppName    string
	Folder     Folder
	FileFormat FileFormat
}

Dot is the main struct of dot configuration library. Create with the dot.New() function.

func New

func New() *Dot

New creates a new dot struct with default values. default app name is current executable name default folder type is HomeDir default FileFormat is yaml

func (*Dot) ByFileFormat

func (d *Dot) ByFileFormat(ff FileFormat) *Dot

ByFileFormat set file format enum to Dot struct

func (*Dot) ByFolder

func (d *Dot) ByFolder(f Folder) *Dot

ByFolder set Folder enum to Dot struct

func (*Dot) Dump

func (d *Dot) Dump() error

Dump prints Dot struct for debugging

func (*Dot) GetConfigFolder

func (d *Dot) GetConfigFolder() (string, error)

GetConfigFolder return full path of config folder

func (*Dot) GetConfigPath

func (d *Dot) GetConfigPath(configuration interface{}) (string, error)

GetConfigPath return full path of config file

func (*Dot) Load

func (d *Dot) Load(configuration interface{}) error

Load loads Configuration from Dot files

func (*Dot) Save

func (d *Dot) Save(configuration interface{}) error

Save saves Confituraion to Dot files

type FileFormat

type FileFormat string

FileFormat Enum

type Folder

type Folder int

Folder Enum

const (
	// HomeDir - user home dir
	HomeDir Folder = iota
	// CurrentDir - current dir
	CurrentDir = iota
)

Jump to

Keyboard shortcuts

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