cfg

package module
v0.0.0-...-844c204 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2017 License: MIT Imports: 6 Imported by: 1

README

cfg

Build Status GoDoc

cfg is the go language common configuration management, support ini, yaml, toml, json and so on.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	// Type is the config type
	Type Type
	// Str is the config string
	Str string
	// Num is the config number
	Num float64
	// Raw is unknow type value
	Raw interface{}
}

Result represents a value that is returned from Get().

func (*Result) Exists

func (this *Result) Exists() bool

Exists returns true if value exists.

func (*Result) Int

func (this *Result) Int(defaultVal ...int) int

Int returns a int representation of the value. It returns 0 if error occurs, or the default value if given.

func (*Result) String

func (this *Result) String(defaultVal ...string) string

String returns a string representation of the value. It returns empty string if error occurs, or the default value if given.

func (*Result) Value

func (this *Result) Value() interface{}

Value returns one of these types:

bool, for config booleans
float64, for config numbers
Number, for config numbers
string, for config string literals
nil, for config null

type Type

type Type int

Type is Result type

const (
	// NotExists is not exists in config
	NotExists Type = iota
	// Null is a null config value
	Null
	// False is a config false boolean
	False
	// True is a config true boolean
	True
	// Number is config number
	Number
	// String is a config string
	String
	// Interface is the unknow value
	Interface
)

func (Type) String

func (t Type) String() string

String returns a string representation of the type.

type YamlConfig

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

YamlConfig represents a yaml configure. The root must be map.

func ParseYaml

func ParseYaml(file string) (*YamlConfig, error)

ParseYaml parses yaml file into YamlConfig, return error (not nil) if failure.

func (*YamlConfig) Bool

func (this *YamlConfig) Bool(key string) (bool, error)

Bool returns bool type value. It returns an error and false if the key does not exist.

func (*YamlConfig) Exists

func (this *YamlConfig) Exists(key string) bool

Exists returns true if key exists.

func (*YamlConfig) Float64

func (this *YamlConfig) Float64(key string) (float64, error)

Float64 returns float64 type value. It returns an error and 0.0 if the key does not exist.

func (*YamlConfig) Get

func (this *YamlConfig) Get(path string) *Result

Get returns bool type value. It returns an error and false if the key does not exist.

func (*YamlConfig) Int

func (this *YamlConfig) Int(key string) (int, error)

Int returns int type value. It returns an error and 0 if the key does not exist.

func (*YamlConfig) Map

func (this *YamlConfig) Map(key string) (map[interface{}]interface{}, error)

Map returns bool type value. It returns an error and false if the key does not exist.

func (*YamlConfig) MustValue

func (this *YamlConfig) MustValue(key string, defaultVal ...string) string

MustValue always returns value without error. It returns empty string if error occurs, or the default value if given.

func (*YamlConfig) Value

func (this *YamlConfig) Value(key string) (string, error)

Value returns the value of the key. It returns an error and empty string value if the key does not exist.

Jump to

Keyboard shortcuts

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