tests/uint65cast/main.go

42 lines
685 B
Go

package main
import (
"encoding/json"
"github.com/spf13/cast"
"log"
)
type msg struct {
Field1 string `json:"field1"`
Extra map[string]interface{} `json:"extra"`
}
func main() {
teststring := `{"field1":"dafdaf","extra":{"uids":[1,2,3,4,5,6,7,8]}}`
var task msg
if err := json.Unmarshal([]byte(teststring), &task); err != nil {
log.Fatal("unmarshall")
}
log.Printf("%#v", task)
uidsUntyped, ok := task.Extra["uids"]
log.Printf("%#v", uidsUntyped)
if !ok {
log.Fatal("unmap")
}
uids, ok := uidsUntyped.([]uint64)
log.Printf("%#v", uids)
uid, _ := cast.ToUint64E(uidI)
if !ok {
log.Print(uids)
log.Fatal("cast")
}
log.Print(uids)
}