Golang go/ast.Ident.IsExported() function example

package go/ast

IsExported reports whether id is an exported Go symbol (that is, whether it begins with an uppercase letter).

Golang go/ast.Ident.IsExported() function usage example

 func inspectFieldTag(f *File, node ast.Node) {
 field := node.(*ast.Field)
 if field.Tag == nil {
 fmt.Println("Field tag empty")
 return
 }
 if len(field.Names) == 0 {
 fmt.Println("Field tag name empty")
 return
 }
 if field.Names[0].IsExported() { // <-- here
 fmt.Println("Field tag id is exported Go symbol")
 return
 }
 }

Reference :

http://golang.org/pkg/go/ast/#Ident.IsExported

Advertisement