Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Created July 2, 2014 17:47
Show Gist options
  • Save probablycorey/ce75df354fdff8d079f4 to your computer and use it in GitHub Desktop.
Save probablycorey/ce75df354fdff8d079f4 to your computer and use it in GitHub Desktop.
go sample
func main() {
flag.Parse()
for _, filename := range flag.Args() {
if isDir(filename) {
lintDir(filename)
} else {
lintFile(filename)
}
}
}
func isDir(filename string) bool {
fi, err := os.Stat(filename)
return err == nil && fi.IsDir()
}
func lintFile(filename string) {
src, err := ioutil.ReadFile(filename)
if err != nil {
log.Printf("Failed reading %v: %v", filename, err)
return
}
l := new(lint.Linter)
ps, err := l.Lint(filename, src)
if err != nil {
log.Printf("Failed parsing %v: %v", filename, err)
return
}
for _, p := range ps {
if p.Confidence >= *minConfidence {
fmt.Printf("%s:%v: %s\n", filename, p.Position, p.Text)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment