qri: github.com/qri-io/qri/base/fill Index | Files

package fill

import "github.com/qri-io/qri/base/fill"

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


Package Files

error_collector.go path_value.go struct.go


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

func GetPathValue Uses

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 Uses

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 Uses

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.

type ArbitrarySetter Uses

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

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

type ErrorCollector Uses

type ErrorCollector struct {
    // contains filtered or unexported fields

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

func NewErrorCollector Uses

func NewErrorCollector() *ErrorCollector

NewErrorCollector creates a new ErrorCollector

func (*ErrorCollector) Add Uses

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 Uses

func (c *ErrorCollector) AsSingleError() error

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

func (*ErrorCollector) PopField Uses

func (c *ErrorCollector) PopField()

PopField removes the most recent field from the current path

func (*ErrorCollector) PushField Uses

func (c *ErrorCollector) PushField(fieldName string)

PushField adds a field to the current path

type FieldError Uses

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 Uses

func (c *FieldError) Error() string

Error displays the text version of the FieldError

Package fill imports 5 packages (graph) and is imported by 2 packages. Updated 2019-07-19. Refresh now. Tools for package owners.