Documentation ¶
Overview ¶
Package conflate is a library that helps to merge and validate data from multiple formats (JSON/YAML/TOML), and multiple locations (filesystem paths and urls).
Index ¶
- Variables
- func JSONUnmarshal(data []byte, out interface{}) error
- func TOMLUnmarshal(data []byte, out interface{}) error
- func YAMLUnmarshal(data []byte, out interface{}) error
- type Conflate
- func (c *Conflate) AddData(data ...[]byte) error
- func (c *Conflate) AddFiles(paths ...string) error
- func (c *Conflate) AddGo(objs ...interface{}) error
- func (c *Conflate) AddURLs(urls ...*url.URL) error
- func (c *Conflate) ApplyDefaults(s *Schema) error
- func (c *Conflate) Expand(expand bool)
- func (c *Conflate) MarshalJSON() ([]byte, error)
- func (c *Conflate) MarshalTOML() ([]byte, error)
- func (c *Conflate) MarshalYAML() ([]byte, error)
- func (c *Conflate) Unmarshal(out interface{}) error
- func (c *Conflate) Validate(s *Schema) error
- type Schema
- type UnmarshallerFunc
- type UnmarshallerFuncs
- type UnmarshallerMap
Constants ¶
This section is empty.
Variables ¶
var Includes = "includes"
Includes is used to specify the top level key that holds the includes array.
var Unmarshallers = UnmarshallerMap{ ".json": {JSONUnmarshal}, ".jsn": {JSONUnmarshal}, ".yaml": {YAMLUnmarshal}, ".yml": {YAMLUnmarshal}, ".toml": {TOMLUnmarshal}, ".tml": {TOMLUnmarshal}, "": {JSONUnmarshal, YAMLUnmarshal, TOMLUnmarshal}, }
Unmarshallers is a list of unmarshalling functions to be used for given file extensions. The unmarshaller slice for the blank file extension is used when no match is found.
Functions ¶
func JSONUnmarshal ¶
JSONUnmarshal unmarshals the data as JSON.
func TOMLUnmarshal ¶
TOMLUnmarshal unmarshals the data as TOML.
func YAMLUnmarshal ¶
YAMLUnmarshal unmarshals the data as YAML.
Types ¶
type Conflate ¶
type Conflate struct {
// contains filtered or unexported fields
}
Conflate contains a 'working' merged data set and optionally a JSON v4 schema.
func FromFiles ¶
FromFiles constructs a new Conflate instance populated with the data from the given files.
func FromURLs ¶
FromURLs constructs a new Conflate instance populated with the data from the given URLs.
func (*Conflate) AddFiles ¶
AddFiles recursively merges the data from the given files into the Conflate instance.
func (*Conflate) AddGo ¶
AddGo recursively merges the given (json-serializable) golang objects into the Conflate instance.
func (*Conflate) AddURLs ¶
AddURLs recursively merges the data from the given urls into the Conflate instance.
func (*Conflate) ApplyDefaults ¶
ApplyDefaults sets any nil or missing values in the data, to the default values defined in the JSON v4 schema.
func (*Conflate) Expand ¶
Expand is an option to automatically expand environment variables in data files.
func (*Conflate) MarshalJSON ¶
MarshalJSON exports the data as JSON.
func (*Conflate) MarshalTOML ¶
MarshalTOML exports the data as TOML.
func (*Conflate) MarshalYAML ¶
MarshalYAML exports the data as YAML.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema contains a JSON v4 schema.
func NewSchemaData ¶
NewSchemaData loads a JSON v4 schema from the given data.
func NewSchemaFile ¶
NewSchemaFile loads a JSON v4 schema from the given path.
func NewSchemaGo ¶
NewSchemaGo creates a Schema instance from a schema represented as a golang object.
func NewSchemaURL ¶
NewSchemaURL loads a JSON v4 schema from the given URL.
func (*Schema) ApplyDefaults ¶
ApplyDefaults adds default values defined in the schema to the data pointed to by pData.
type UnmarshallerFunc ¶
UnmarshallerFunc defines the type of function used for unmarshalling data.
type UnmarshallerFuncs ¶
type UnmarshallerFuncs []UnmarshallerFunc
UnmarshallerFuncs defines the type for a slice of UnmarshallerFunc.
type UnmarshallerMap ¶
type UnmarshallerMap map[string]UnmarshallerFuncs
UnmarshallerMap defines the type of a map of string to UnmarshallerFuncs.