drill

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

This library provides an easy way to access nested struct visible fields relying either on the names of such fields as assigned in the json tags or by their name in the code. It relies on the well known chaining of the keys with dots so, for example, to request the value at `a.b.c` corresponds to expecting the following nested structs:

type Container struct {
    A TypeA `json:"a"`
}

type TypeA struct {
    B TypeB `json:"b"`
}

type TypeB struct {
    C string `json:"c"`
}

The above might also have been references.

There is only one function to do so: Get. It accepts interface{} and returns a tuple (interface{}, error), so it is the caller's responsibility to check for errors and to cast the result in the appropriate type. If, at whichever level, one of the keys in the chain is missing, the Get returns ErrKeyNotFound.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = internal.ErrKeyNotFound

ErrKeyNotFound indicates that the key

Functions

func Get

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

Get espects the struct to be accessed as first argument an the chain of keys as second argument. It panics if the first input is not a struct or a reference to a struct or a map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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