Documentation
¶
Overview ¶
Package strconvex is an extension to strconv package that implements a common interface for converting text to simple Go values using reflect to guess type information and strconv for actual conversion.
As in strconv, only simple Go types are supported with a few minor helpful additions that help with compound types but have the limitation that only the first level is parsed and their elements or fields must be simple types.
As input, standard GoValue format from the fmt package is understood.
Index ¶
- Variables
- func StringToArrayValue(in string, out reflect.Value) error
- func StringToBoolValue(in string, out reflect.Value) error
- func StringToComplex128Value(in string, out reflect.Value) error
- func StringToComplex64Value(in string, out reflect.Value) error
- func StringToFloat32Value(in string, out reflect.Value) error
- func StringToFloat64Value(in string, out reflect.Value) error
- func StringToIntValue(in string, out reflect.Value) error
- func StringToInterface(in string, out interface{}) error
- func StringToMapValue(in string, out reflect.Value) error
- func StringToPointerValue(in string, out reflect.Value) error
- func StringToSliceValue(in string, out reflect.Value) error
- func StringToStringValue(in string, out reflect.Value) error
- func StringToStructValue(in string, out reflect.Value) error
- func StringToUintValue(in string, out reflect.Value) error
- func StringToValue(in string, out reflect.Value) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidValue = errors.New("strconvex: invalid value")
ErrInvalidValue is returned when an invalid value is specified.
Functions ¶
func StringToArrayValue ¶
StringToArrayValue converts a string to an array. String is of the form "elem1,elem2,elemN". Elements must be simple values.
func StringToBoolValue ¶
StringToBoolValue converts a string to a bool.
func StringToComplex128Value ¶
StringToComplex128Value converts a string to a complex128.
func StringToComplex64Value ¶
StringToComplex64Value converts a string to a complex64.
func StringToFloat32Value ¶
StringToFloat32Value converts a string to a float32.
func StringToFloat64Value ¶
StringToFloat64Value converts a string to a float64.
func StringToIntValue ¶
StringToIntValue converts a string to a int of any width.
func StringToInterface ¶
StringToInterface converts string in to out which must be a pointer to a Go value conversion compatible to data contained in string. See StringToValue for details.
func StringToMapValue ¶
StringToMapValue converts a string to a map. String is of the form: "key1=val1,key2=val2,keyN=valN". Elements must be simple values.
func StringToPointerValue ¶
StringToPointerValue converts a string to a pointer.
func StringToSliceValue ¶
StringToSliceValue converts a string to a slice. String is of the form "elem1,elem2,elemN". Elements must be simple values.
func StringToStringValue ¶
StringToStringValue converts a string to a string.
func StringToStructValue ¶
StringToStructValue converts a string to a struct. String is of the form: "{field1=value1,field2=value2,fieldN=valueN}" Fields must be simple values.
func StringToUintValue ¶
StringToUintValue converts a string to an uint of any width.
func StringToValue ¶
StringToValue converts string in to out reflect.Value whose type must be conversion compatible to in string.
Compound types are supported on first level only and must have simple types as elements. Simple parsing rules are defined as follows and reserve the comma ',', equals '=', left brace'{' and right brace '}' characters for interpreting the compound types. Compound values are specified as follows:
Array and Slice: Values delimited by comma. Example: 0,1,2,3,4
Map: Key=Value pairs delimited by comma. Example:key1=value1,key2=value2,keyN=valueN
Struct: Map of values enclosed in braces. Example:{field1=foo,field2=42,fieldN=valueN}
Invalid syntax for compound values, or Chans and Func values as input values will result in an error.
Types ¶
This section is empty.