dotnotation

package
v0.0.0-...-2d3612e Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dotnotation provides dot notation getters and setters for manipulating data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGetter

func DefaultGetter(target interface{}, property string) (interface{}, error)

DefaultGetter returns the property value of a given target, or an error, supporting types like encoding/json. Supports one level of pointer indirection.

func DefaultParser

func DefaultParser(key string) []string

DefaultParser simply converts a string key into a list of properties that must be accessed in order, to achieve the dot notation get or set.

func DefaultSetter

func DefaultSetter(target interface{}, property string, value interface{}) error

DefaultSetter sets the property value of a given target, to a given value, or returns an error, supporting types like encoding/json. Supports one level of pointer indirection, and appending to slices if a pointer is used.

func Get

func Get(target interface{}, key string) (interface{}, error)

Get sets a value using dot notation, by default it supports generic []interface{} and map[string]interface{} types. It's behaviour can be configured by modifying the DefaultAccessor variable.

func Set

func Set(target interface{}, key string, value interface{}) error

Set sets a value using dot notation, by default it supports generic []interface{} and map[string]interface{} types. It's behaviour can be configured by modifying the DefaultAccessor variable.

Types

type Accessor

type Accessor struct {
	// Getter returns the property value of a given target, or an error.
	Getter func(target interface{}, property string) (interface{}, error)
	// Setter sets the property value of a given target, to a given value, or returns an error.
	Setter func(target interface{}, property string, value interface{}) error
	// Parser converts a given key into a list of properties to access in order to get or set.
	Parser func(key string) []string
}

Accessor provides two methods, Get and Set, that can be configured to handle custom data structures via the exported properties, Parser, Getter, and Setter.

var DefaultAccessor Accessor

DefaultAccessor, used for the exported Set and Get functions.

func (Accessor) Get

func (p Accessor) Get(target interface{}, key string) (interface{}, error)

func (Accessor) Set

func (p Accessor) Set(target interface{}, key string, value interface{}) error

Jump to

Keyboard shortcuts

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