mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 23:00:55 +00:00
commit
dae2a36eb5
33
parser.go
33
parser.go
@ -23,7 +23,7 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -56,8 +56,9 @@ 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, _ = filepath.Rel(AppPath, pkgRealpath)
|
||||||
|
commentFilename = coomentPrefix + rep.Replace(commentFilename) + ".go"
|
||||||
if !compareFile(pkgRealpath) {
|
if !compareFile(pkgRealpath) {
|
||||||
logs.Info(pkgRealpath + " no changed")
|
logs.Info(pkgRealpath + " no changed")
|
||||||
return nil
|
return nil
|
||||||
@ -87,7 +88,7 @@ func parserPkg(pkgRealpath, pkgpath string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
genRouterCode()
|
genRouterCode(pkgRealpath)
|
||||||
savetoFile(pkgRealpath)
|
savetoFile(pkgRealpath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -130,8 +131,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)
|
||||||
logs.Info("generate router from comments")
|
logs.Info("generate router from comments")
|
||||||
var (
|
var (
|
||||||
globalinfo string
|
globalinfo string
|
||||||
@ -173,7 +174,7 @@ func genRouterCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if globalinfo != "" {
|
if globalinfo != "" {
|
||||||
f, err := os.Create(path.Join(AppPath, "routers", commentFilename))
|
f, err := os.Create(filepath.Join(getRouterDir(pkgRealpath), commentFilename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ func genRouterCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func compareFile(pkgRealpath string) bool {
|
func compareFile(pkgRealpath string) bool {
|
||||||
if !utils.FileExists(path.Join(AppPath, "routers", commentFilename)) {
|
if !utils.FileExists(filepath.Join(getRouterDir(pkgRealpath), commentFilename)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.FileExists(lastupdateFilename) {
|
if utils.FileExists(lastupdateFilename) {
|
||||||
@ -230,3 +231,19 @@ 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 := filepath.Join(dir, "routers")
|
||||||
|
if utils.FileExists(d) {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
if r, _ := filepath.Rel(dir, AppPath); r == "." {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
// Parent dir.
|
||||||
|
dir = filepath.Dir(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -73,6 +73,10 @@ func (e *Error) String() string {
|
|||||||
return e.Message
|
return e.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement Error interface.
|
||||||
|
// Return e.String()
|
||||||
|
func (e *Error) Error() string { return e.String() }
|
||||||
|
|
||||||
// Result is returned from every validation method.
|
// Result is returned from every validation method.
|
||||||
// It provides an indication of success, and a pointer to the Error (if any).
|
// It provides an indication of success, and a pointer to the Error (if any).
|
||||||
type Result struct {
|
type Result struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user