reflectutil

package
v1.20240719.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package reflectutil includes helpers for working with the golang reflection api.

Index

Constants

View Source
const (
	// FieldTagEnv is the struct tag for what environment variable to use to populate a field.
	FieldTagEnv = "env"
	// FieldFlagCSV is a field tag flag (say that 10 times fast).
	FieldFlagCSV = "csv"
	// FieldFlagBase64 is a field tag flag (say that 10 times fast).
	FieldFlagBase64 = "base64"
	// FieldFlagBytes is a field tag flag (say that 10 times fast).
	FieldFlagBytes = "bytes"
)

PatchStrings options.

Variables

This section is empty.

Functions

func DecomposeStrings

func DecomposeStrings(obj interface{}, tagName ...string) map[string]string

DecomposeStrings decomposes an object into a string map.

func FollowValue

func FollowValue(v reflect.Value) interface{}

FollowValue derefs a reflect.Value until it isn't a pointer, but will preseve it's nilness.

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

IsEmptyValue returns if a reflect.Value is empty.

func IsExported

func IsExported(fieldName string) bool

IsExported returns if a field is exported given its name and capitalization.

func Patch

func Patch(obj interface{}, patchValues map[string]interface{}) (err error)

Patch updates an object based on a map of field names to values.

func PatchStrings

func PatchStrings(tagName string, data map[string]string, obj interface{}) error

PatchStrings patches an object with a given map of data matched with tags of a given name or the name of the field.

func PatchStringsFunc

func PatchStringsFunc(tagName string, getData func(string) (string, bool), obj interface{}) (err error)

PatchStringsFunc patches an object with a given map of data matched with tags of a given name or the name of the field.

func SetValue

func SetValue(obj interface{}, objType reflect.Type, objValue reflect.Value, fieldName string, value interface{}) (err error)

SetValue sets a value on an object by its field name.

func SliceType

func SliceType(collection interface{}) reflect.Type

SliceType returns the inner type of a slice following pointers.

func Type

func Type(obj interface{}) reflect.Type

Type returns the reflect type following pointers.

func Value

func Value(obj interface{}) reflect.Value

Value returns the reflect value following pointers.

Types

type PatchStringer

type PatchStringer interface {
	PatchStrings(map[string]string) error
}

PatchStringer is a type that handles unmarshalling a map of strings into itself.

type PatchStringsFuncer

type PatchStringsFuncer interface {
	PatchStringsFunc(func(string) (string, bool)) error
}

PatchStringsFuncer is a type that handles unmarshalling a map of strings into itself.

type Patcher

type Patcher interface {
	Patch(map[string]interface{}) error
}

Patcher describes an object that can be patched with raw values.

Jump to

Keyboard shortcuts

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