config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 4 Imported by: 0

README

config

Contains functions for loading configurations and handling data.

data encapsulation

Substation encapsulates data during ingest and decapsulates it during load; data in transit is stored in "capsules." Capsules contain two fields:

  • data: stores structured or unstructured data
  • metadata: stores structured metadata that describes the data

The metadata field is accessed through a special JSON key named "!metadata", any references to this key will get or set the structured data stored in the field. JSON values can be freely moved between the data and metadata fields.

Capsules can be created and initialized using this pattern, where b is a []byte and v is an interface{}:

	cap := NewCapsule()
	cap.SetData(b).SetMetadata(v)

Substation applications follow these rules when handling capsules:

  • Sources set the initial metadata, but this can be modified in transit by applying processors
  • Sinks only output data, but metadata can be retained by copying it from metadata into data

Documentation

Index

Constants

View Source
const SetInvalidKey = errors.Error("SetInvalidKey")

SetInvalidKey is returned when an invalid key is used in a Capsule Set function.

Variables

This section is empty.

Functions

func Decode

func Decode(input interface{}, output interface{}) error

Decode marshals and unmarshals an input interface into the output interface using the standard library's json package. This should be used when decoding JSON configurations (i.e., Config) in Substation interface factories.

Types

type Capsule

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

Capsule stores encapsulated data that is used throughout the package's data handling and processing functions.

Each capsule contains two unexported fields that are accessed by getters and setters:

- data: stores structured or unstructured data

- metadata: stores structured metadata that describes the data

Values in the metadata field are accessed using the pattern "!metadata [key]". JSON values can be freely moved between the data and metadata fields.

Capsules can be created and initialized using this pattern, where b is a []byte and v is an interface{}:

cap := NewCapsule()
cap.SetData(b).SetMetadata(v)

Substation applications follow these rules when handling capsules:

- Sources set the initial metadata, but this can be modified in transit by applying processors

- Sinks only output data, but metadata can be retained by copying it from metadata into data

func NewCapsule

func NewCapsule() Capsule

NewCapsule returns a new, empty Capsule.

func (*Capsule) Delete

func (c *Capsule) Delete(key string) (err error)

Delete removes a key from a JSON object stored in the capsule's data or metadata fields.

func (*Capsule) Get

func (c *Capsule) Get(key string) json.Result

Get retrieves a value from a JSON object stored in the capsule's data or metadata fields.

func (*Capsule) GetData

func (c *Capsule) GetData() []byte

GetData returns the contents of the capsule's data field.

func (*Capsule) GetMetadata

func (c *Capsule) GetMetadata() []byte

GetMetadata returns the contents of the capsule's metadata field.

func (*Capsule) Set

func (c *Capsule) Set(key string, value interface{}) (err error)

Set writes a value to a JSON object stored in the capsule's data or metadata fields.

func (*Capsule) SetData

func (c *Capsule) SetData(b []byte) *Capsule

SetData writes data to the capsule's data field.

func (*Capsule) SetMetadata

func (c *Capsule) SetMetadata(i interface{}) (*Capsule, error)

SetMetadata writes data to the capsule's metadata field. Metadata must be an interface that can marshal to a JSON object.

func (*Capsule) SetRaw

func (c *Capsule) SetRaw(key string, value interface{}) (err error)

SetRaw writes a raw value to a JSON object stored in the capsule's data or metadata fields. These values are usually pre-formatted JSON (e.g., entire objects or arrays).

type Config

type Config struct {
	Type     string                 `json:"type"`
	Settings map[string]interface{} `json:"settings"`
}

Config is a template used by Substation interface factories to produce new instances from JSON configurations. Type refers to the type of instance and Settings contains options used in the instance. Examples of this are found in the condition and process packages.

Jump to

Keyboard shortcuts

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