Documentation ¶
Overview ¶
Package jsonconfig defines a helper type for JSON objects to be used for configuration.
Index ¶
- func RegisterFunc(name string, fn func(c *ConfigParser, v []interface{}) (interface{}, error))
- type ConfigParser
- type File
- type Obj
- func (jc Obj) OptionalBool(key string, def bool) bool
- func (jc Obj) OptionalInt(key string, def int) int
- func (jc Obj) OptionalInt64(key string, def int64) int64
- func (jc Obj) OptionalList(key string) []string
- func (jc Obj) OptionalObject(key string) Obj
- func (jc Obj) OptionalString(key, def string) string
- func (jc Obj) OptionalStringOrObject(key string) interface{}
- func (jc Obj) RequiredBool(key string) bool
- func (jc Obj) RequiredInt(key string) int
- func (jc Obj) RequiredInt64(key string) int64
- func (jc Obj) RequiredList(key string) []string
- func (jc Obj) RequiredObject(key string) Obj
- func (jc Obj) RequiredString(key string) string
- func (jc Obj) RequiredStringOrObject(key string) interface{}
- func (jc Obj) UnknownKeys() []string
- func (jc Obj) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFunc ¶
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.
Types ¶
type ConfigParser ¶
type ConfigParser struct { // Open optionally specifies an opener function. Open func(filename string) (File, error) // contains filtered or unexported fields }
ConfigParser specifies the environment for parsing a config file and evaluating expressions.
func (*ConfigParser) CheckTypes ¶
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.
type File ¶
type File interface { io.ReadSeeker io.Closer Name() string }
A File is the type returned by ConfigParser.Open.
type Obj ¶
type Obj map[string]interface{}
Obj is a JSON configuration map.
func (Obj) OptionalList ¶
func (Obj) OptionalObject ¶
func (Obj) OptionalString ¶
func (Obj) OptionalStringOrObject ¶
func (Obj) RequiredBool ¶
func (Obj) RequiredInt ¶
func (Obj) RequiredInt64 ¶
func (Obj) RequiredList ¶
func (Obj) RequiredObject ¶
func (Obj) RequiredString ¶
func (Obj) RequiredStringOrObject ¶
func (Obj) UnknownKeys ¶
UnknownKeys returns the keys from the config that have not yet been discovered by one of the RequiredT or OptionalT calls.