cast icon indicating copy to clipboard operation
cast copied to clipboard

ToSliceE: unable to cast []somestruct to []interface{}

Open dionysius opened this issue 3 years ago • 0 comments

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.

dionysius avatar Jun 25 '21 21:06 dionysius