String parsing package for Go. Converts strings to best guess value type.
Supported types (in this order):
nil
ornull
bool
int
int64
uint
uint64
float64
Quoted values are always strings with the quotes stripped.
For examples see the test code.
go get gopkg.in/matryer/str.v1
The simplest usage:
val := str.Parse("123")
To add additional ParseFunc
functions:
parser := append(str.DefaultParser, toMyRangeType)
val := parser.Parse("[1,3]")
To use your own parsers entirely, use New
:
parser := str.New(toMyRangeType)
val := parser.Parse("[1,3]")
To add parsers for time, import the parsers
package and use the Time
method:
parser := append(str.DefaultParser, parsers.Time(time.RFC822))
val := parser.Parse("02 Jan 06 15:04 MST")