mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:50:58 +00:00
Change comment router file info
This commit is contained in:
parent
1642cbd420
commit
272271f588
28
parser.go
28
parser.go
@ -24,6 +24,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ func init() {
|
|||||||
|
|
||||||
func parserPkg(pkgRealpath, pkgpath string) error {
|
func parserPkg(pkgRealpath, pkgpath string) error {
|
||||||
rep := strings.NewReplacer("/", "_", ".", "_")
|
rep := strings.NewReplacer("/", "_", ".", "_")
|
||||||
commentFilename = coomentPrefix + rep.Replace(pkgpath) + ".go"
|
commentFilename = coomentPrefix + rep.Replace(strings.Replace(pkgRealpath, AppPath, "", -1)) + ".go"
|
||||||
if !compareFile(pkgRealpath) {
|
if !compareFile(pkgRealpath) {
|
||||||
Info(pkgRealpath + " no changed")
|
Info(pkgRealpath + " no changed")
|
||||||
return nil
|
return nil
|
||||||
@ -86,7 +87,7 @@ func parserPkg(pkgRealpath, pkgpath string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
genRouterCode()
|
genRouterCode(pkgRealpath)
|
||||||
savetoFile(pkgRealpath)
|
savetoFile(pkgRealpath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -129,8 +130,8 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genRouterCode() {
|
func genRouterCode(pkgRealpath string) {
|
||||||
os.Mkdir(path.Join(AppPath, "routers"), 0755)
|
os.Mkdir(getRouterDir(pkgRealpath), 0755)
|
||||||
Info("generate router from comments")
|
Info("generate router from comments")
|
||||||
var (
|
var (
|
||||||
globalinfo string
|
globalinfo string
|
||||||
@ -172,7 +173,7 @@ func genRouterCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if globalinfo != "" {
|
if globalinfo != "" {
|
||||||
f, err := os.Create(path.Join(AppPath, "routers", commentFilename))
|
f, err := os.Create(path.Join(getRouterDir(pkgRealpath), commentFilename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ func genRouterCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func compareFile(pkgRealpath string) bool {
|
func compareFile(pkgRealpath string) bool {
|
||||||
if !utils.FileExists(path.Join(AppPath, "routers", commentFilename)) {
|
if !utils.FileExists(path.Join(getRouterDir(pkgRealpath), commentFilename)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.FileExists(lastupdateFilename) {
|
if utils.FileExists(lastupdateFilename) {
|
||||||
@ -229,3 +230,18 @@ func getpathTime(pkgRealpath string) (lastupdate int64, err error) {
|
|||||||
}
|
}
|
||||||
return lastupdate, nil
|
return lastupdate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRouterDir(pkgRealpath string) string {
|
||||||
|
dir := filepath.Dir(pkgRealpath)
|
||||||
|
for {
|
||||||
|
d := path.Join(dir, "routers")
|
||||||
|
if dir == AppPath {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
if utils.FileExists(d) {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
// Parent dir.
|
||||||
|
dir = filepath.Dir(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user