go4.org: go4.org/jsonconfig Index | Files

package jsonconfig

import "go4.org/jsonconfig"

Package jsonconfig defines a helper type for JSON objects to be used for configuration.

Index

Package Files

eval.go jsonconfig.go

func RegisterFunc Uses

func RegisterFunc(name string, fn func(c *ConfigParser, v []interface{}) (interface{}, error))

RegisterFunc registers a new function that may be called from JSON configs using an array of the form ["_name", arg0, argN...]. The provided name must begin with an underscore.

type ConfigParser Uses

type ConfigParser struct {

    // Open optionally specifies an opener function.
    Open func(filename string) (File, error)

    // IncludeDirs optionally specifies where to find the other config files which are child
    // objects of this config, if any. Even if nil, the working directory is always searched
    // first.
    IncludeDirs []string
    // contains filtered or unexported fields
}

ConfigParser specifies the environment for parsing a config file and evaluating expressions.

func (*ConfigParser) CheckTypes Uses

func (c *ConfigParser) CheckTypes(m map[string]interface{}) error

CheckTypes parses m and returns an error if it encounters a type or value that is not supported by this package.

func (*ConfigParser) ConfigFilePath Uses

func (c *ConfigParser) ConfigFilePath(configFile string) (path string, err error)

ConfigFilePath checks if configFile is found and returns a usable path to it. It first checks if configFile is an absolute path, or if it's found in the current working directory. If not, it then checks if configFile is in one of c.IncludeDirs. It returns an error if configFile is absolute and could not be statted, or os.ErrNotExist if configFile was not found.

func (*ConfigParser) ReadFile Uses

func (c *ConfigParser) ReadFile(path string) (Obj, error)

ReadFile parses the provided path and returns the config file. If path is empty, the c.Open function must be defined.

type File Uses

type File interface {
    io.ReadSeeker
    io.Closer
    Name() string
}

A File is the type returned by ConfigParser.Open.

type Obj Uses

type Obj map[string]interface{}

Obj is a JSON configuration map.

func ReadFile Uses

func ReadFile(configPath string) (Obj, error)

ReadFile reads JSON config data from the specified open file, expanding all expressions. Use *ConfigParser.ReadFile instead if you need to set c.IncludeDirs.

func (Obj) OptionalBool Uses

func (jc Obj) OptionalBool(key string, def bool) bool

func (Obj) OptionalInt Uses

func (jc Obj) OptionalInt(key string, def int) int

func (Obj) OptionalInt64 Uses

func (jc Obj) OptionalInt64(key string, def int64) int64

func (Obj) OptionalList Uses

func (jc Obj) OptionalList(key string) []string

func (Obj) OptionalObject Uses

func (jc Obj) OptionalObject(key string) Obj

func (Obj) OptionalString Uses

func (jc Obj) OptionalString(key, def string) string

func (Obj) OptionalStringOrObject Uses

func (jc Obj) OptionalStringOrObject(key string) interface{}

func (Obj) RequiredBool Uses

func (jc Obj) RequiredBool(key string) bool

func (Obj) RequiredInt Uses

func (jc Obj) RequiredInt(key string) int

func (Obj) RequiredInt64 Uses

func (jc Obj) RequiredInt64(key string) int64

func (Obj) RequiredList Uses

func (jc Obj) RequiredList(key string) []string

func (Obj) RequiredObject Uses

func (jc Obj) RequiredObject(key string) Obj

func (Obj) RequiredString Uses

func (jc Obj) RequiredString(key string) string

func (Obj) RequiredStringOrObject Uses

func (jc Obj) RequiredStringOrObject(key string) interface{}

func (Obj) UnknownKeys Uses

func (jc Obj) UnknownKeys() []string

UnknownKeys returns the keys from the config that have not yet been discovered by one of the RequiredT or OptionalT calls.

func (Obj) Validate Uses

func (jc Obj) Validate() error

Package jsonconfig imports 14 packages (graph) and is imported by 147 packages. Updated 2016-07-18. Refresh now. Tools for package owners.