Use idiomatic error messaging and variable naming, and don't make unnecessary changes.
This commit is contained in:
parent
b89a8c9df8
commit
d79b636dff
10
jsonenums.go
10
jsonenums.go
@ -92,16 +92,16 @@ func main() {
|
|||||||
types := strings.Split(*typeNames, ",")
|
types := strings.Split(*typeNames, ",")
|
||||||
|
|
||||||
// Only one directory at a time can be processed, and the default is ".".
|
// Only one directory at a time can be processed, and the default is ".".
|
||||||
inDir := "."
|
dir := "."
|
||||||
if args := flag.Args(); len(args) == 1 {
|
if args := flag.Args(); len(args) == 1 {
|
||||||
inDir = args[0]
|
dir = args[0]
|
||||||
} else if len(args) > 1 {
|
} else if len(args) > 1 {
|
||||||
log.Fatalf("only one directory at a time")
|
log.Fatalf("only one directory at a time")
|
||||||
}
|
}
|
||||||
dir, err := filepath.Abs(inDir)
|
dir, err := filepath.Abs(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to determine absolute filepath for requested path %s: %v",
|
log.Fatalf("unable to determine absolute filepath for requested path %s: %v",
|
||||||
inDir, err)
|
dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg, err := parser.ParsePackage(dir)
|
pkg, err := parser.ParsePackage(dir)
|
||||||
|
@ -36,11 +36,11 @@ func ParsePackage(directory string) (*Package, error) {
|
|||||||
build.Default.GOPATH, err)
|
build.Default.GOPATH, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
loaderConf := loader.Config{TypeChecker: types.Config{FakeImportC: true}}
|
conf := loader.Config{TypeChecker: types.Config{FakeImportC: true}}
|
||||||
loaderConf.Import(relDir)
|
conf.Import(relDir)
|
||||||
program, err := loaderConf.Load()
|
program, err := conf.Load()
|
||||||
if err != nil {
|
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)
|
pkgInfo := program.Package(relDir)
|
||||||
|
@ -47,7 +47,7 @@ func generateHandler(w http.ResponseWriter, r *http.Request) error {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
pkg, err := parser.ParsePackage(dir, "", "")
|
pkg, err := parser.ParsePackage(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("parse package: %v", err)
|
return fmt.Errorf("parse package: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user