Check if Golang interface is a slice

This function returns true if the given interface is a slice, otherwise it returns false.

func InterfaceIsSlice(t interface{}) bool {
	switch reflect.TypeOf(t).Kind() {
	case reflect.Slice:
		return true
	default:
		return false
	}
}Code language: PHP (php)
CategoriesGo

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.