fill

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: GPL-3.0 Imports: 5 Imported by: 1

Documentation

Overview

Package fill assigns arbitrary values to struct fields using reflection. "fill" is case-insensitive, and obeys the "json" field tag if present. It's primary use is to support decoding data from a number of serialization formats (JSON,YAML,CBOR) into an intermediate map[string]interface{} value which can then be used to "fill" arbitrary struct values

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a field isn't found
	ErrNotFound = fmt.Errorf("not found")
)

Functions

func GetPathValue

func GetPathValue(path string, input interface{}) (interface{}, error)

GetPathValue gets a value from the input struct, accessed using the path of dot-separated fields

func SetPathValue

func SetPathValue(path string, val interface{}, output interface{}) error

SetPathValue sets a value on a the output struct, accessed using the path of dot-separated fields

func Struct

func Struct(fields map[string]interface{}, output interface{}) error

Struct fills in the values of an arbitrary structure using an already deserialized map of nested data. Fields names are case-insensitive. Unknown fields are treated as an error, *unless* the output structure implements the ArbitrarySetter interface.

Types

type ArbitrarySetter

type ArbitrarySetter interface {
	SetArbitrary(string, interface{}) error
}

ArbitrarySetter should be implemented by structs that can store arbitrary fields in a private map.

type ErrorCollector added in v0.8.0

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

ErrorCollector collects errors, merging them into one, while noting the path where they happen

func NewErrorCollector added in v0.8.0

func NewErrorCollector() *ErrorCollector

NewErrorCollector creates a new ErrorCollector

func (*ErrorCollector) Add added in v0.8.0

func (c *ErrorCollector) Add(err error) bool

Add adds a non-nil error to the ErrorCollector, noting the path where the error happened

func (*ErrorCollector) AsSingleError added in v0.8.0

func (c *ErrorCollector) AsSingleError() error

AsSingleError returns the collected errors as a single error, or nil if there are none

func (*ErrorCollector) PopField added in v0.8.0

func (c *ErrorCollector) PopField()

PopField removes the most recent field from the current path

func (*ErrorCollector) PushField added in v0.8.0

func (c *ErrorCollector) PushField(fieldName string)

PushField adds a field to the current path

type FieldError added in v0.8.0

type FieldError struct {
	Got  string
	Want string
	Val  interface{}
}

FieldError represents an error when a value does not match the expected type

func (*FieldError) Error added in v0.8.0

func (c *FieldError) Error() string

Error displays the text version of the FieldError

Jump to

Keyboard shortcuts

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