cast
cast copied to clipboard
ToSliceE: unable to cast []somestruct to []interface{}
Playground: https://play.golang.org/p/5bbxzoB4jNw
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: %+v\n", bees)
}
type B struct {
Foo string
}
panic: unable to cast []main.B{main.B{Foo:"one"}, main.B{Foo:"two"}} of type []main.B to []interface{}
goroutine 1 [running]:
main.main()
/tmp/sandbox460370487/prog.go:14 +0x157
Program exited: status 2.