cast
cast copied to clipboard
safe and easy casting from one type to another in Go
add function `ToInt64SliceE` to support convert slice to `[]int64`
https://github.com/spf13/cast/blob/88075729b052bca4b8b6c31bf198db2fe6c9da93/caste.go#L81-L99 there only assert type `int`, no `int8`, `int16`, `int32`, `int64`, `uint` ... could we add these type case?
eg: a := "0100" b := cast.ToInt(a) fmt.Println(b) the result is 64 but what i want is 100
I have a value id=16607535815717977617: ```go id1 := cast.ToString(id) // -1839208257991573999 id2 := strconv.FormatUint(id, 10) // 16607535815717977617 ``` which is an unexpected behavior.
Allow to convert string with size units (such as "10kb") to bytes. This converter is privately used in viper. I think it is great to allow using it from cast....
I needed something like this for a project, and wanted to share with you if you would like 🙂
https://play.golang.org/p/5kUZwo1uV9W ```go package main import ( "fmt" "github.com/spf13/cast" ) func main() { fmt.Printf("%#v\n", cast.ToIntSlice(nil)) fmt.Printf("%#v\n", cast.ToStringSlice(nil)) } ``` Output: ``` []int{} []string(nil) ``` In first line an **empty** slice returned,...
```shell git clone https://github.com/spf13/cast && cd cast && go test . ``` ``` go: downloading github.com/stretchr/testify v1.2.2 --- FAIL: TestToTimeWithTimezones (0.02s) --- FAIL: TestToTimeWithTimezones/3;timeFormatType=1;Mon,_02_Jan_2006_15:04:05_MST (0.00s) --- FAIL: TestToTimeWithTimezones/3;timeFormatType=1;Mon,_02_Jan_2006_15:04:05_MST/local_timezone_without_a_default_location (0.00s) require.go:157:...
This would be pretty nice building block for reflect type casting; something like: ``` cast.ToReflectValue(i interface{}, value reflect.Values) error ```