I've got a function to which I want to feed different kinds of slices after which I want to loop over them and print their contents. The following code works:
func plot(data interface{}){
fmt.Println(data)
//fmt.Println(len(data))
}
func main() {
l := []int{1, 4, 3}
plot(l)
}
But when I uncomment the line in which I print the length of the slice, I get an error saying invalid argument data (type interface {}) for len
.
Any idea how I would be able to get the length of the slice so that I can loop over it?