Golang go/parser.Mode type example

package go/parser

A Mode value is a set of flags (or 0). They control the amount of source code parsed and other optional parser functionality.

Golang go/parser.Mode type usage example

 func doDir(name string) {
  notests := func(info os.FileInfo) bool {
 if !info.IsDir() && strings.HasSuffix(info.Name(), ".go") &&
 !strings.HasSuffix(info.Name(), "_test.go") {
 return true
 }
 return false
  }
  fs := token.NewFileSet()
  pkgs, err := parser.ParseDir(fs, name, notests, parser.Mode(0))
  if err != nil {
 errorf("%s", err)
 return
  }
  for _, pkg := range pkgs {
 doPackage(fs, pkg)
  }
 }

References :

https://gowalker.org/github.com/remyoudompheng/go-misc/deadcode?f=deadcode.go

http://golang.org/pkg/go/parser/#Mode

Advertisement