Created
March 25, 2019 02:13
-
-
Save Matts966/7142c0188bae04b49d2a623151826c35 to your computer and use it in GitHub Desktop.
Check the value is slice or not in golang.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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