cast
cast copied to clipboard
safe and easy casting from one type to another in Go
parser string to int64 should use strconv.ParseInt(trimZeroDecimal(s), 10, 64) not the follow; v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0) if err == nil { return v, nil }
in numeric value's switch-case logic, maybe can support json.Number, now it will return an error
version: 1.5 1.3 ``` test.proto enum N { DEFAULT = 0; ONE = 1; } message Test { N num = 1; } ``` ``` main.go a := &pb.Test{ Num:...
func ToUint64E(i interface{}) (uint64, error) use the v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0) error:strconv.ParseInt: parsing "11166014772858028509": value out of range unable to cast "11166014772858028509" of type string to uint64 `case...
``` // You can edit this code! // Click here and start typing. package main import ( "fmt" "github.com/spf13/cast" ) type Hoge = string type Fuga string func main() {...
Here is my sample code. I tried to turn SampleReq into a map[string]string. However,map["array"] turns out to be empty. I checked the code and found ToStringE() is unable to handle...
for example,string is "00011",handle ToInt("00011"),want to get int value is 11,now return 9; need exchange caste.go trimZeroDecimal method,first trimleft zero func trimZeroDecimal(s string) string { s = strings.TrimLeft(s, "0") var...
Hello everyone. I'm facing the issue is I cannot convert the alias type to int32. This is an example ``` package main import ( "testing" "github.com/spf13/cast" "github.com/stretchr/testify/require" ) type a...
`package main import ( "fmt" "strconv" "github.com/spf13/cast" ) func main() { for i := 0; i