How to get all defined types?

前端 未结 4 1249
我在风中等你
我在风中等你 2020-12-21 03:10
package demo

type People struct {
    Name string
    Age  uint
}

type UserInfo struct {
    Address  string
    Hobby           


        
4条回答
  •  [愿得一人]
    2020-12-21 04:17

    Using go/importer:

    pkg, err := importer.Default().Import("time")
    if err != nil {
        fmt.Println("error:", err)
        return
    }
    for _, declName := range pkg.Scope().Names() {
        fmt.Println(declName)
    }
    

    (note, this returns an error on the Go Playground).

提交回复
热议问题