conflate: github.com/miracl/conflate Index | Files | Directories

package conflate

import "github.com/miracl/conflate"

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

Package Files

conflate.go context.go doc.go error.go filedata.go format.go loader.go marshal.go merge.go schema.go

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.

func JSONUnmarshal Uses

func JSONUnmarshal(data []byte, out interface{}) error

JSONUnmarshal unmarshals the data as JSON

func TOMLUnmarshal Uses

func TOMLUnmarshal(data []byte, out interface{}) error

TOMLUnmarshal unmarshals the data as TOML

func YAMLUnmarshal Uses

func YAMLUnmarshal(data []byte, out interface{}) error

YAMLUnmarshal unmarshals the data as YAML

type Conflate Uses

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

Conflate contains a 'working' merged data set and optionally a JSON v4 schema

func FromData Uses

func FromData(data ...[]byte) (*Conflate, error)

FromData constructs a new Conflate instance populated with the given data

func FromFiles Uses

func FromFiles(paths ...string) (*Conflate, error)

FromFiles constructs a new Conflate instance populated with the data from the given files

func FromGo Uses

func FromGo(data ...interface{}) (*Conflate, error)

FromGo constructs a new Conflate instance populated with the given golang objects

func FromURLs Uses

func FromURLs(urls ...url.URL) (*Conflate, error)

FromURLs constructs a new Conflate instance populated with the data from the given URLs

func New Uses

func New() *Conflate

New constructs a new empty Conflate instance

func (*Conflate) AddData Uses

func (c *Conflate) AddData(data ...[]byte) error

AddData recursively merges the given data into the Conflate instance

func (*Conflate) AddFiles Uses

func (c *Conflate) AddFiles(paths ...string) error

AddFiles recursively merges the data from the given files into the Conflate instance

func (*Conflate) AddGo Uses

func (c *Conflate) AddGo(objs ...interface{}) error

AddGo recursively merges the given (json-serializable) golang objects into the Conflate instance

func (*Conflate) AddURLs Uses

func (c *Conflate) AddURLs(urls ...url.URL) error

AddURLs recursively merges the data from the given urls into the Conflate instance

func (*Conflate) ApplyDefaults Uses

func (c *Conflate) ApplyDefaults(s *Schema) error

ApplyDefaults sets any nil or missing values in the data, to the default values defined in the JSON v4 schema

func (*Conflate) Expand Uses

func (c *Conflate) Expand(expand bool)

Expand is an option to automatically expand environment variables in data files

func (*Conflate) MarshalJSON Uses

func (c *Conflate) MarshalJSON() ([]byte, error)

MarshalJSON exports the data as JSON

func (*Conflate) MarshalTOML Uses

func (c *Conflate) MarshalTOML() ([]byte, error)

MarshalTOML exports the data as TOML

func (*Conflate) MarshalYAML Uses

func (c *Conflate) MarshalYAML() ([]byte, error)

MarshalYAML exports the data as YAML

func (*Conflate) Unmarshal Uses

func (c *Conflate) Unmarshal(out interface{}) error

Unmarshal extracts the data as a Golang object

func (*Conflate) Validate Uses

func (c *Conflate) Validate(s *Schema) error

Validate checks the data against the JSON v4 schema

type Schema Uses

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

Schema contains a JSON v4 schema

func NewSchemaData Uses

func NewSchemaData(data []byte) (*Schema, error)

NewSchemaData loads a JSON v4 schema from the given data

func NewSchemaFile Uses

func NewSchemaFile(path string) (*Schema, error)

NewSchemaFile loads a JSON v4 schema from the given path

func NewSchemaGo Uses

func NewSchemaGo(s interface{}) (*Schema, error)

NewSchemaGo creates a Schema instance from a schema represented as a golang object

func NewSchemaURL Uses

func NewSchemaURL(url url.URL) (*Schema, error)

NewSchemaURL loads a JSON v4 schema from the given URL

func (*Schema) ApplyDefaults Uses

func (s *Schema) ApplyDefaults(pData interface{}) error

ApplyDefaults adds default values defined in the schema to the data pointed to by pData

func (*Schema) Validate Uses

func (s *Schema) Validate(data interface{}) error

Validate checks the given golang data against the schema

type UnmarshallerFunc Uses

type UnmarshallerFunc func([]byte, interface{}) error

UnmarshallerFunc defines the type of function used for unmarshalling data

type UnmarshallerFuncs Uses

type UnmarshallerFuncs []UnmarshallerFunc

UnmarshallerFuncs defines the type for a slice of UnmarshallerFunc

type UnmarshallerMap Uses

type UnmarshallerMap map[string]UnmarshallerFuncs

UnmarshallerMap defines the type of a map of string to UnmarshallerFuncs

Directories

PathSynopsis
conflate
example

Package conflate imports 23 packages (graph) and is imported by 4 packages. Updated 2019-02-13. Refresh now. Tools for package owners.