reflectutil

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

reflectutil

The package contains various helpers for reflection

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructField

func GetStructField(structInstance interface{}, fieldname string) reflect.Value

GetStructField obtains a reference to a field of a pointer to a struct

func GetUnexportedField

func GetUnexportedField(structInstance interface{}, fieldname string) interface{}

GetUnexportedField unwraps an unexported field with pointer to struct and field name

func SetUnexportedField

func SetUnexportedField(structInstance interface{}, fieldname string, value interface{})

SetUnexportedField sets (pointer to) struct's field with the specified value

func ToMap

func ToMap(v interface{}, tomapkey ToMapKey, unexported bool) (map[string]interface{}, error)

ToMap converts exported fields of a struct to map[string]interface{} - non exported fields are converted to string

func ToMapWithDefault

func ToMapWithDefault(v interface{}) (map[string]interface{}, error)

ToMapWithDefault settings

func UnwrapUnexportedField

func UnwrapUnexportedField(field reflect.Value) interface{}

UnwrapUnexportedField unwraps an unexported field

Types

type ToMapKey

type ToMapKey func(string) string
var TitleUnderscore ToMapKey = func(raw string) string {
	newstr := make([]rune, 0, len(raw))
	for i, chr := range raw {
		if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
			if i > 0 {
				newstr = append(newstr, '_')
			}
			chr -= 'A' - 'a'
		}
		newstr = append(newstr, chr)
	}
	return string(newstr)
}

TitleUnderscore from https://github.com/go-ini/ini/blob/5e97220809ffaa826f787728501264e9114cb834/struct.go#L46

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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