https://github.com/matryer/str
String parsing package for Go. Converts strings to best guess value type.
https://github.com/matryer/str
Last synced: 6 months ago
JSON representation
String parsing package for Go. Converts strings to best guess value type.
- Host: GitHub
- URL: https://github.com/matryer/str
- Owner: matryer
- License: mit
- Created: 2015-08-28T10:33:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-31T09:31:06.000Z (over 9 years ago)
- Last Synced: 2024-11-01T20:21:14.842Z (6 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# str [](https://godoc.org/github.com/matryer/str)
String parsing package for Go. Converts strings to best guess value type.Supported types (in this order):
* `nil` or `null`
* `bool`
* `int`
* `int64`
* `uint`
* `uint64`
* `float64`Quoted values are always strings with the quotes stripped.
For examples see the [test code](https://github.com/matryer/str/blob/master/str_test.go#L11-L115).
## Get started
```
go get gopkg.in/matryer/str.v1
```## Usage
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]")
```### Time
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")
```