Help us shape the future of Go! Take the 2026 Go Developer Survey

reflectutil

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 3 Imported by: 1

README

iputil

The package contains various helpers for reflection

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

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

Jump to

Keyboard shortcuts

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