Skip to content

Instantly share code, notes, and snippets.

@Matts966
Created March 25, 2019 02:13
Show Gist options
  • Save Matts966/7142c0188bae04b49d2a623151826c35 to your computer and use it in GitHub Desktop.
Save Matts966/7142c0188bae04b49d2a623151826c35 to your computer and use it in GitHub Desktop.
Check the value is slice or not in golang.
package main
import (
"fmt"
"reflect"
)
func check(a interface{}) bool {
fmt.Println(a)
val := reflect.ValueOf(a)
fmt.Println(val.Kind())
if val.Kind() == reflect.Slice {
return true
}
return false
}
func main() {
fmt.Println(check([]struct{A string}{struct{A string}{A: "aaa"}}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment