drill

package module
v2.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 a generic type T and returns a tuple (V, error), where V is a generic type too. If, at whichever level, one of the keys in the chain is missing, the Get returns drill.ErrKeyNotFound.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = internal.ErrKeyNotFound

ErrKeyNotFound indicates that the key

Functions

func Get

func Get[T, V any](input T, key string) (V, error)

Get is the function to use to access the fields of nested structs. It espects two inputs: the first of type T is the struct (or map) and the second is the dotted notation version of the successions of keys to access the field. The two generics are (T) the type of the input and (V) the type of the field being accessed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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