mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
Internalize parsePackagesFromDir()
This commit is contained in:
parent
a68e8ae3e8
commit
c562cedf96
@ -102,8 +102,8 @@ func init() {
|
|||||||
astPkgs = make([]*ast.Package, 0)
|
astPkgs = make([]*ast.Package, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePackagesFromDir parses packages from a given directory
|
// parsePackagesFromDir parses packages from a given directory
|
||||||
func ParsePackagesFromDir(dirpath string) {
|
func parsePackagesFromDir(dirpath string) {
|
||||||
c := make(chan error)
|
c := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -157,8 +157,14 @@ func parsePackageFromDir(path string) error {
|
|||||||
|
|
||||||
// GenerateDocs generates documentations for a given path.
|
// GenerateDocs generates documentations for a given path.
|
||||||
func GenerateDocs(curpath string) {
|
func GenerateDocs(curpath string) {
|
||||||
fset := token.NewFileSet()
|
pkgspath := curpath
|
||||||
|
workspace := os.Getenv("BeeWorkspace")
|
||||||
|
if workspace != "" {
|
||||||
|
pkgspath = workspace
|
||||||
|
}
|
||||||
|
parsePackagesFromDir(pkgspath)
|
||||||
|
|
||||||
|
fset := token.NewFileSet()
|
||||||
f, err := parser.ParseFile(fset, filepath.Join(curpath, "routers", "router.go"), nil, parser.ParseComments)
|
f, err := parser.ParseFile(fset, filepath.Join(curpath, "routers", "router.go"), nil, parser.ParseComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Fatalf("Error while parsing router.go: %s", err)
|
beeLogger.Log.Fatalf("Error while parsing router.go: %s", err)
|
||||||
|
15
main.go
15
main.go
@ -21,19 +21,10 @@ import (
|
|||||||
"github.com/beego/bee/cmd"
|
"github.com/beego/bee/cmd"
|
||||||
"github.com/beego/bee/cmd/commands"
|
"github.com/beego/bee/cmd/commands"
|
||||||
"github.com/beego/bee/config"
|
"github.com/beego/bee/config"
|
||||||
"github.com/beego/bee/generate/swaggergen"
|
|
||||||
"github.com/beego/bee/utils"
|
"github.com/beego/bee/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
workspace = os.Getenv("BeeWorkspace")
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
currentpath, _ := os.Getwd()
|
|
||||||
if workspace != "" {
|
|
||||||
currentpath = workspace
|
|
||||||
}
|
|
||||||
flag.Usage = cmd.Usage
|
flag.Usage = cmd.Usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
@ -66,12 +57,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.LoadConfig()
|
config.LoadConfig()
|
||||||
|
|
||||||
// Check if current directory is inside the GOPATH,
|
|
||||||
// if so parse the packages inside it.
|
|
||||||
if cmd.IfGenerateDocs(c.Name(), args) {
|
|
||||||
swaggergen.ParsePackagesFromDir(currentpath)
|
|
||||||
}
|
|
||||||
os.Exit(c.Run(c, args))
|
os.Exit(c.Run(c, args))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user