strconvex

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 5 Imported by: 2

README

strconvex

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.

The api consists of the following:

func StringToInterface(in string, out interface{})
func StringToValue(in string, out reflect.Value)
func StringToBoolValue(in string, out reflect.Value)
func StringToIntValue(in string, out reflect.Value)
func StringToUintValue(in string, out reflect.Value)
func StringToFloat32Value(in string, out reflect.Value)
func StringToFloat64Value(in string, out reflect.Value)
func StringToComplex64Value(in string, out reflect.Value)
func StringToComplex128Value(in string, out reflect.Value)
func StringToStringValue(in string, out reflect.Value)
func StringToArrayValue(in string, out reflect.Value)
func StringToSliceValue(in string, out reflect.Value)
func StringToMapValue(in string, out reflect.Value)
func StringToStructValue(in string, out reflect.Value)
func StringToPointerValue(in string, out reflect.Value)

License

MIT. See included LICENSE file.

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

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("strconvex: invalid value")

ErrInvalidValue is returned when an invalid value is specified.

Functions

func StringToArrayValue

func StringToArrayValue(in string, out reflect.Value) error

StringToArrayValue converts a string to an array. String is of the form "elem1,elem2,elemN". Elements must be simple values.

func StringToBoolValue

func StringToBoolValue(in string, out reflect.Value) error

StringToBoolValue converts a string to a bool.

func StringToComplex128Value

func StringToComplex128Value(in string, out reflect.Value) error

StringToComplex128Value converts a string to a complex128.

func StringToComplex64Value

func StringToComplex64Value(in string, out reflect.Value) error

StringToComplex64Value converts a string to a complex64.

func StringToFloat32Value

func StringToFloat32Value(in string, out reflect.Value) error

StringToFloat32Value converts a string to a float32.

func StringToFloat64Value

func StringToFloat64Value(in string, out reflect.Value) error

StringToFloat64Value converts a string to a float64.

func StringToIntValue

func StringToIntValue(in string, out reflect.Value) error

StringToIntValue converts a string to a int of any width.

func StringToInterface

func StringToInterface(in string, out interface{}) error

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

func StringToMapValue(in string, out reflect.Value) error

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

func StringToPointerValue(in string, out reflect.Value) error

StringToPointerValue converts a string to a pointer.

func StringToSliceValue

func StringToSliceValue(in string, out reflect.Value) error

StringToSliceValue converts a string to a slice. String is of the form "elem1,elem2,elemN". Elements must be simple values.

func StringToStringValue

func StringToStringValue(in string, out reflect.Value) error

StringToStringValue converts a string to a string.

func StringToStructValue

func StringToStructValue(in string, out reflect.Value) error

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

func StringToUintValue(in string, out reflect.Value) error

StringToUintValue converts a string to an uint of any width.

func StringToValue

func StringToValue(in string, out reflect.Value) error

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.

Jump to

Keyboard shortcuts

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