Created
July 2, 2014 17:47
-
-
Save probablycorey/ce75df354fdff8d079f4 to your computer and use it in GitHub Desktop.
go sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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