config

package module
v0.0.0-...-14c562f Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 12 Imported by: 3

README

Config for GO projects

Simple universal config xml, json, yaml

Config example

app:
  name: App1
  version: 1.0.3beta
  description: "Description text"

  params:
    p1: v1
    p2: v2

  arr:
    - value1
    - value2
    - value3

Get

conf, _ := config.From(map)

v, err := conf.Get("app.*.p1")
fmt.Println(v) // v1

Set

conf, _ := config.From(map[string]interface{}{})

conf.Set("array.+", "Item 1")
conf.Set("array.+", "Item 2")
conf.Set("array.+", "Item 3")

fmt.Println(conf.JsonString())
{"array":["Item 1", "Item 3", "Item 2"]}
conf.Set("array.$", "New Value")
fmt.Println(conf.JsonString())
{"array":["New Value", "New Value", "New Value"]}
conf.Set("array.$.map", "New Value")
fmt.Println(conf.JsonString())
{"array":["New Value", "New Value", "New Value", {"map": "Nev Value"}]}

License

The MIT License (MIT)

Copyright (c) 2015 Dmiptry Ponomarev <demdxx@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPath         = errors.New("Invalid path")
	ErrNoValue             = errors.New("No value")
	ErrNoValid             = errors.New("No valid")
	ErrInvalidConfigFormat = errors.New("Invalid config format")
)

Functions

func BoolOrDefault

func BoolOrDefault(path string, def bool) bool

func Float64OrDefault

func Float64OrDefault(path string, def float64) float64

func Get

func Get(path string) (interface{}, error)

func GetDefault

func GetDefault(path string, def interface{}) interface{}

func GetPath

func GetPath(path []string) (interface{}, error)

func HasGlobalConfig

func HasGlobalConfig(code string) bool

func IntOrDefault

func IntOrDefault(path string, def int) int

func SetGlobalConfig

func SetGlobalConfig(code string, conf Config)

func String

func String(path string) string

func StringOrDefault

func StringOrDefault(path string, def string) string

Types

type Config

type Config map[string]interface{}

func From

func From(c interface{}) (Config, error)

func FromData

func FromData(data []byte, dtype string) (conf Config, err error)

func FromFile

func FromFile(filename, ftype string) (Config, error)

func FromQuick

func FromQuick(c interface{}) (Config, error)

func Global

func Global() Config

func GlobalByFile

func GlobalByFile(filename, ftype string) (Config, error)

func GlobalByName

func GlobalByName(code string) Config

func New

func New() Config

func Set

func Set(path string, value interface{}) Config

func SetGlobalByFile

func SetGlobalByFile(code, filename, ftype string) (Config, error)

func SetPath

func SetPath(path []string, value interface{}) Config

func (Config) BoolOrDefault

func (conf Config) BoolOrDefault(path string, def bool) bool

func (Config) Float64OrDefault

func (conf Config) Float64OrDefault(path string, def float64) float64

func (Config) Get

func (conf Config) Get(path string) (interface{}, error)

func (Config) GetDefault

func (conf Config) GetDefault(path string, def interface{}) interface{}

func (Config) GetPath

func (conf Config) GetPath(path []string) (interface{}, error)

func (Config) IntOrDefault

func (conf Config) IntOrDefault(path string, def int) int

func (Config) JSON

func (conf Config) JSON() ([]byte, error)

func (Config) JSONPrettify

func (conf Config) JSONPrettify() ([]byte, error)

func (Config) Prepare

func (conf Config) Prepare(escLeft, escRight string)

func (Config) Set

func (conf Config) Set(path string, value interface{}) Config

func (Config) SetPath

func (conf Config) SetPath(fullpath []string, value interface{}) Config

func (Config) String

func (conf Config) String(path string) string

func (Config) StringOrDefault

func (conf Config) StringOrDefault(path string, def string) string

func (Config) Update

func (conf Config) Update(conf2 Config) Config

func (Config) UpdateByPath

func (conf Config) UpdateByPath(path string) Config

type ConfigArr

type ConfigArr []interface{}

func FromSliceQuick

func FromSliceQuick(c interface{}) (ConfigArr, error)

func (ConfigArr) Get

func (conf ConfigArr) Get(path string) (interface{}, error)

func (ConfigArr) GetPath

func (conf ConfigArr) GetPath(path []string) (interface{}, error)

func (ConfigArr) Set

func (conf ConfigArr) Set(path string, value interface{}) ConfigArr

func (ConfigArr) SetPath

func (conf ConfigArr) SetPath(path []string, value interface{}) ConfigArr

Jump to

Keyboard shortcuts

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