如何在Golang中的包下获取所有结构?

Can we list all struct in the form of name or interface, under a package? Like:

struct := list("fmt")

expected result:

Formatter
GoStringer
Scanner
State
Stringer

The best you can do is parse the go sources (which you can clone: hg clone https://code.google.com/p/go/), and isolate the ast.StructType.

That is what a pretty printer does:

func (P *Printer) Type(t *AST.Type) int {
    separator := semicolon;

    switch t.form {

    case AST.STRUCT, AST.INTERFACE:
            switch t.form {
            case AST.STRUCT: P.String(t.pos, "struct");
            case AST.INTERFACE: P.String(t.pos, "interface");
            }
            if t.list != nil {
                    P.separator = blank;
                    P.Fields(t.list, t.end);
            }
            separator = none;

In the same idea, the linter go/lint does the same in lint.go:

    case *ast.StructType:
        for _, f := range v.Fields.List {
            for _, id := range f.Names {
                check(id, "struct field")
            }
        }
    }