conflate

package module
v0.0.0-...-b774f33 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

CONFLATE

Library providing routines to merge and validate JSON, YAML, TOML files and/or structs (godoc)

Build Status Coverage Status Go Report Card

Description

Conflate is a library that provides the following features :

  • merge data from multiple formats (JSON/YAML/TOML/go structs) and multiple locations (filesystem paths and urls)
  • validate the merged data against a JSON schema
  • apply any default values defined in a JSON schema to the merged data
  • expand environment variables inside the data
  • marshal merged data to multiple formats (JSON/YAML/TOML/go structs)

Data files can include other files using the includes array, meaning that they will be merged (i.e. in JSON this is simply a string array at the top-level). The includes array can support multiple path types (see below), including relative paths to local or remote files. Values present in the containing file override those from any file in the includes array, and values from any file in the includes array override those from files before it in the includes array :

{
  "includes": [
    "./myfile.json",
    "/etc/myfolder/myfile.yaml",
    "file://etc/myfolder/myfile.toml",
    "http://mydomain/myfile"
  ],
  "mydata": 123
}

Usage

For basic usage refer to the example, or use the cli tool

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

Constants

This section is empty.

Variables

View Source
var Includes = "includes"

Includes is used to specify the top level key that holds the includes array

View Source
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

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

JSONUnmarshal unmarshals the data as JSON

func TOMLUnmarshal

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

TOMLUnmarshal unmarshals the data as TOML

func YAMLUnmarshal

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

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 FromData

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

FromData constructs a new Conflate instance populated with the given data

func FromFiles

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

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

func FromGo

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

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

func FromURLs

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

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

func New

func New() *Conflate

New constructs a new empty Conflate instance

func (*Conflate) AddData

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

AddData recursively merges the given data into the Conflate instance

func (*Conflate) AddFiles

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

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

func (*Conflate) AddGo

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

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

func (*Conflate) AddURLs

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

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

func (*Conflate) ApplyDefaults

func (c *Conflate) ApplyDefaults() error

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

func (*Conflate) Expand

func (c *Conflate) Expand(expand bool)

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

func (*Conflate) MarshalJSON

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

MarshalJSON exports the data as JSON

func (*Conflate) MarshalSchema

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

MarshalSchema exports the schema as JSON

func (*Conflate) MarshalTOML

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

MarshalTOML exports the data as TOML

func (*Conflate) MarshalYAML

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

MarshalYAML exports the data as YAML

func (*Conflate) SetSchemaData

func (c *Conflate) SetSchemaData(data []byte) error

SetSchemaData loads a JSON v4 schema from the given data

func (*Conflate) SetSchemaFile

func (c *Conflate) SetSchemaFile(path string) error

SetSchemaFile loads a JSON v4 schema from the given path

func (*Conflate) SetSchemaURL

func (c *Conflate) SetSchemaURL(url url.URL) error

SetSchemaURL loads a JSON v4 schema from the given URL

func (*Conflate) Unmarshal

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

Unmarshal extracts the data as a Golang object

func (*Conflate) Validate

func (c *Conflate) Validate() error

Validate checks the data against the JSON v4 schema

type UnmarshallerFunc

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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