cast
cast copied to clipboard
safe and easy casting from one type to another in Go
Playground: https://play.golang.org/p/5bbxzoB4jNw ```golang package main import ( "fmt" "github.com/spf13/cast" ) func main() { b := []B{{Foo: "one"},{Foo: "two"}} bees, err := cast.ToSliceE(b) if err != nil { panic(err) } fmt.Printf("bees:...
Add the possibility to cast a slice into a hashset (`map[string]struct{}`). The `struct{}` element worth 0 byte, and it's really useful for checking if a key is present. [here an...
per discussion in issue #112 it probably requires more discussion on if this is a desired change... it was a terribly simple change but I'm not personally aware of the...
```go var value = "00100" fmt.Println(strconv.ParseInt(value, 10, 64)) fmt.Println(strconv.Atoi(value)) fmt.Println(cast.ToInt64E(value)) fmt.Println(cast.ToIntE(value)) ``` output ```shell 100 ✅ 100 ✅ 64 ❌ 64 ❌ ``` ```go var value = "012345678" fmt.Println(strconv.ParseInt(value, 10,...
func `ToString` support json serialize
ToStringE can't cast a variable of basic type redefiniton to string, such as ` type IntAlias int var i IntAlias = 8 str, err := ToStringE(i) // get an error...
Added power support for the travis.yml file with ppc64le. This is part of the Ubuntu distribution for ppc64le. This helps us simplify testing later when distributions are re-building and re-releasing
ToInt64E currently try cast the value to int type, which default to int32 type on 32-bit system and will result in potential overflow error. Fix this by update the bitSize...
Git log by default uses it's own human format [Sat May 8 19:35:34 2010 -0500][1]. This adds support for parsing this format. [1]: https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-log.html
```go package main import ( "fmt" "github.com/spf13/cast" ) func main() { a := map[string]string{"hello": "123"} r := cast.ToStringMapInt(a) fmt.Printf("%T %#v\n", r, r) r = cast.ToStringMapInt(&a) fmt.Printf("%T %#v\n", r, r) }...