setstruct

package
v0.0.0-...-9d95335 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StringParserMap = map[reflect.Type]StringParser{}

StringParserMap is the map from reflect type to a string parser.

View Source
var UpdaterType = reflect.TypeOf((*Updater)(nil)).Elem()

UpdaterType is the reflect type of Assigner interface.

Functions

func ParseBool

func ParseBool(s string) bool

ParseBool parses string s as a bool.

func ParseFloat64

func ParseFloat64(s string) (float64, bool)

ParseFloat64 parses string s as float64.

func ParseInt64

func ParseInt64(s string) (int64, bool)

ParseInt64 parses string s as int64.

func ParseStringToStringMap

func ParseStringToStringMap(val string, kkSep, kvSep string) map[string]string

ParseStringToStringMap parses a string to string map from a string.

func RegisterStringParser

func RegisterStringParser(typ reflect.Type, parser StringParser)

RegisterStringParser registers a string parser to a reflect type.

func Set

func Set(dstStructPtr interface{}, valueGenerator func(reflect.StructField) string)

Set set struct fields by valueGenerator.

func SetField

func SetField(f reflect.Value, v string)

SetField set struct field by its string representation.

Types

type StringParser

type StringParser func(s string) (reflect.Value, error)

StringParser is the func prototype to parse a string s to a reflect value.

type Updater

type Updater interface {
	// ValueOf assigned by string s to the pointer receiver.
	ValueOf(s string) error
}

Updater is the interface for a struct pointer receiver to be assigned a value by string s.

Jump to

Keyboard shortcuts

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