github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/hammers/extractiface.go (about) 1 // +build ignore 2 3 package main 4 5 import ( 6 "fmt" 7 "go/ast" 8 "go/parser" 9 "go/token" 10 ) 11 12 func main() { 13 src := `package hack; import "net/http"; var i http.Handler` 14 f, _ := parser.ParseFile(token.NewFileSet(), "", src, 0) 15 16 decl := f.Decls[1].(*ast.GenDecl) // var i http.Handler 17 spec := decl.Specs[0].(*ast.ValueSpec) // i http.Handler 18 sel := spec.Type.(*ast.SelectorExpr) // http.Handler 19 id := sel.Sel.Name // Handler 20 fmt.Println(id) 21 }