How to determine if type is a struct in Golang

前端 未结 1 2043
情书的邮戳
情书的邮戳 2021-02-09 13:40

Suppose i have 2 structs :

type Base struct {
 id int
 name string
}

type Extended struct {
 Base
 Email string
 Password string
}

And i want

相关标签:
1条回答
  • 2021-02-09 14:12

    Just check the Kind() of Value

    if reflect.ValueOf(e).Field(i).Kind() != reflect.Struct {
        fmt.Println(reflect.ValueOf(e).Field(i))
    }
    
    0 讨论(0)
提交回复
热议问题