Use idiomatic error messaging and variable naming, and don't make unnecessary changes.

This commit is contained in:
Benjamin Pflanz 2016-05-11 12:02:21 -04:00
parent b89a8c9df8
commit d79b636dff
3 changed files with 10 additions and 10 deletions

View File

@ -92,16 +92,16 @@ func main() {
types := strings.Split(*typeNames, ",")
// Only one directory at a time can be processed, and the default is ".".
inDir := "."
dir := "."
if args := flag.Args(); len(args) == 1 {
inDir = args[0]
dir = args[0]
} else if len(args) > 1 {
log.Fatalf("only one directory at a time")
}
dir, err := filepath.Abs(inDir)
dir, err := filepath.Abs(dir)
if err != nil {
log.Fatalf("Unable to determine absolute filepath for requested path %s: %v",
inDir, err)
log.Fatalf("unable to determine absolute filepath for requested path %s: %v",
dir, err)
}
pkg, err := parser.ParsePackage(dir)

View File

@ -36,11 +36,11 @@ func ParsePackage(directory string) (*Package, error) {
build.Default.GOPATH, err)
}
loaderConf := loader.Config{TypeChecker: types.Config{FakeImportC: true}}
loaderConf.Import(relDir)
program, err := loaderConf.Load()
conf := loader.Config{TypeChecker: types.Config{FakeImportC: true}}
conf.Import(relDir)
program, err := conf.Load()
if err != nil {
return nil, fmt.Errorf("Couldn't load package: %v", err)
return nil, fmt.Errorf("couldn't load package: %v", err)
}
pkgInfo := program.Package(relDir)

View File

@ -47,7 +47,7 @@ func generateHandler(w http.ResponseWriter, r *http.Request) error {
}
defer os.RemoveAll(dir)
pkg, err := parser.ParsePackage(dir, "", "")
pkg, err := parser.ParsePackage(dir)
if err != nil {
return fmt.Errorf("parse package: %v", err)
}