https://github.com/webern/go-value
A simpler any-like structure in Go
https://github.com/webern/go-value
Last synced: about 1 month ago
JSON representation
A simpler any-like structure in Go
- Host: GitHub
- URL: https://github.com/webern/go-value
- Owner: webern
- License: mit
- Created: 2019-04-28T21:48:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-30T15:49:34.000Z (about 7 years ago)
- Last Synced: 2025-01-24T21:25:07.927Z (over 1 year ago)
- Language: Go
- Size: 46.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
go-value
========
Value wraps a fixed set of very common types in a static-typed-friendly way. It frees you up from using `interface{}` for a lot of use cases where you don't know the type you will receive (e.g. JSON).
It looks like this:
```
v := Value{}
v.IsNull() // true
v.IsInt() // false
v.SetInt(5)
v.IsInt() // true
v.Int() // 5
v.String() // ""
v.IsString() // false
v.SetString("Hello Value")
v.IsString() // true
v.String() // "Hello Value"
```
This is a simple package. I may break the API though so this is version zero.
#### TODO
In particular I want to change the functions like `CoerceToBool` to be pure standalone functions instead of member functions.