Golang go/ast.Decl type examples
package go/ast
All declaration nodes implement the Decl interface.
Golang go/ast.Decl type usage examples
Example 1:
func ParseDecl(x string) (ast.Decl, error) {
file, err := parser.ParseFile(token.NewFileSet(), "", "package p\n//line :1\n"+x+"\n", 0)
if err != nil {
return nil, err
}
return file.Decls[0], nil
}
Example 2:
func (check *Checker) declStmt(decl ast.Decl) {
pkg := check.pkg
switch d := decl.(type) {
case *ast.BadDecl:
// ignore
case *ast.GenDecl:
// do something
...
}
References :
http://golang.org/pkg/go/ast/#Decl
https://github.com/shurcooL/go/blob/master/gists/gist5707298/main.go
Advertisement
Something interesting
Tutorials
+7.8k Golang : Regular Expression find string example
+31.7k Golang : How to convert(cast) string to IP address?
+15.2k Golang : Get timezone offset from date or timestamp
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+21.4k Curl usage examples with Golang
+25.7k Golang : How to write CSV data to file
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+18.8k Golang : How to make function callback or pass value from function as parameter?
+7.1k Golang : Gorrila mux.Vars() function example
+11.6k Golang : Display a text file line by line with line number example
+5.7k Fix yum-complete-transaction error
+11.1k Golang : Simple image viewer with Go-GTK