mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 21:34:14 +01:00
20 lines
380 B
Go
20 lines
380 B
Go
package gogen
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/gobuffalo/genny"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func PackageName(f genny.File) (string, error) {
|
|
pkg := filepath.Base(filepath.Dir(f.Name()))
|
|
pf, err := ParseFile(f)
|
|
if err == nil {
|
|
pkg = pf.Ast.Name.String()
|
|
}
|
|
if len(pkg) == 0 || pkg == "." {
|
|
return "", errors.New("could not determine package")
|
|
}
|
|
return pkg, nil
|
|
}
|