data

package
v0.0.0-...-ec9fd1c Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2012 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

The data package has various ways to work with generic data. It was designed for YAML data, but many of the same functions are useful for generic mappings and such.

Index

Constants

View Source
const (
	StringTag   = parser.DefaultPrefix + "str"
	SequenceTag = parser.DefaultPrefix + "seq"
	MappingTag  = parser.DefaultPrefix + "map"

	NullTag  = parser.DefaultPrefix + "null"
	BoolTag  = parser.DefaultPrefix + "bool"
	IntTag   = parser.DefaultPrefix + "int"
	FloatTag = parser.DefaultPrefix + "float"
)

Canonical YAML tags

Variables

This section is empty.

Functions

func AsBool

func AsBool(data interface{}) (b bool, ok bool)

AsBool converts an untyped value to a boolean.

func AsFloat

func AsFloat(data interface{}) (f float64, ok bool)

AsFloat converts an untyped value to a floating-point number.

func AsInt

func AsInt(data interface{}) (i int, ok bool)

AsInt converts an untyped value to a signed integer.

func AsInt64

func AsInt64(data interface{}) (i int64, ok bool)

AsInt64 converts an untyped value to a int64.

func AsUint

func AsUint(data interface{}) (i uint, ok bool)

AsUint converts an untyped value to an unsigned integer.

func AsUint64

func AsUint64(data interface{}) (i uint64, ok bool)

AsUint64 converts an untyped value to a uint64.

Types

type Constructor

type Constructor parser.Constructor

A Constructor converts a Node into a Go data structure.

var DefaultConstructor Constructor = ConstructorMap{
	StringTag:   ConstructorFunc(constructStr),
	SequenceTag: ConstructorFunc(constructSeq),
	MappingTag:  ConstructorFunc(constructMap),
	NullTag:     ConstructorFunc(constructNull),
	BoolTag:     ConstructorFunc(constructBool),
	IntTag:      ConstructorFunc(constructInt),
	FloatTag:    ConstructorFunc(constructFloat),
}

DefaultConstructor constructs all of the core data types.

type ConstructorFunc

type ConstructorFunc func(parser.Node, interface{}) (interface{}, error)

ConstructorFunc is a function that implements the Constructor interface.

func (ConstructorFunc) Construct

func (f ConstructorFunc) Construct(n parser.Node, userData interface{}) (interface{}, error)

type ConstructorMap

type ConstructorMap map[string]Constructor

ConstructorMap uses constructors associated with string tags to construct a value.

func (ConstructorMap) Construct

func (m ConstructorMap) Construct(n parser.Node, userData interface{}) (data interface{}, err error)

type Map

type Map map[interface{}]interface{}

Map is an unordered collection of values associated with key values.

func AsMap

func AsMap(data interface{}) (m Map, ok bool)

AsMap converts an untyped value to a map of values.

func (Map) Copy

func (m Map) Copy() (clone Map)

CopyMap creates a shallow copy of a map.

func (Map) HasKeys

func (m Map) HasKeys(keys ...interface{}) bool

HasKeys returns whether a given map contains all of the keys given.

func (Map) SetDefault

func (m Map) SetDefault(k, d interface{}) (v interface{})

SetDefault adds a new key to a map if the key isn't already present, and returns the latest value for the key.

type Schema

type Schema parser.Schema

A Schema determines the tag for a node without an explicit tag.

var (
	FailsafeSchema Schema = SchemaFunc(failsafeSchema)
	CoreSchema            = SchemaFunc(coreSchema)
)

Schemas from the YAML 1.2 specification

type SchemaFunc

type SchemaFunc func(node parser.Node, userData interface{}) (tag string, err error)

SchemaFunc is a function type that fulfills the Schema interface.

func (SchemaFunc) Resolve

func (f SchemaFunc) Resolve(n parser.Node, userData interface{}) (string, error)

type Sequence

type Sequence []interface{}

Sequence is an ordered collection of values.

func AsSequence

func AsSequence(data interface{}) (seq Sequence, ok bool)

AsSequence converts an untyped value to a sequence of values.

Jump to

Keyboard shortcuts

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