如何检查外部类型是否是内部类型?

If I have different forms of user structs being passed around my application is there a way to check if that embedded struct is a type of the outer struct?

type (
    user struct {
        name  string
        email string
    }
    admin struct {
        user
        level string
    }
)

Depending on you need, you have two main methods: reflect.TypeOf, and the type swtich.

You will use the first to compare the type of an interface with another one. Example:

if reflect.TypeOf(a) == reflect.TypeOf(b) {
    doSomething()
}

You will use the second to do a particular action given the type of an interface. Example:

switch a.(type) {
    case User:
        doSomething()
    case Admin:
        doSomeOtherThing()
}