1
0
mirror of https://github.com/beego/bee.git synced 2025-07-05 13:10:18 +00:00

bug fixed

This commit is contained in:
JessonChan
2016-03-25 10:55:00 +08:00
parent 8c09cfbe63
commit 2b797200df

17
fix.go
View File

@ -220,6 +220,11 @@ func fixFile(file string) error {
}
func fixLogModule(fixed string) string {
const gitHubBeego = `"github.com/astaxie/beego"` + "\n"
const gitHubLogs = `"github.com/astaxie/beego/logs"` + "\n"
if strings.Contains(fixed, gitHubLogs) {
return fixed
}
logReplacer := []string{
"beego.LevelEmergency", "logs.LevelEmergency",
"beego.LevelAlert", "logs.LevelAlert",
@ -279,20 +284,22 @@ func fixLogModule(fixed string) string {
break
}
}
const gitHubBeego = `"github.com/astaxie/beego"` + "\n"
const gitHubLogs = `"github.com/astaxie/beego/logs"` + "\n"
if !needBeego {
return strings.Replace(fixed, gitHubBeego, gitHubLogs, -1)
}
slash = false
newFixed := ""
startImport := false
inserted := false
lines := strings.Split(fixed, "\n")
for num, line := range lines {
if num == len(lines)-1 && (line == "" || line == "\n") {
continue
}
newFixed += line + "\n"
if inserted {
continue
}
if strings.HasPrefix(line, "import") {
if strings.HasPrefix(line, "import (") {
slash = true
@ -300,12 +307,14 @@ func fixLogModule(fixed string) string {
} else {
if strings.Contains(line, gitHubBeego) {
newFixed += `import "github.com/astaxie/beego/logs"` + "\n"
inserted = true
}
}
}
if !startImport {
continue
}
if slash {
if strings.Contains(line, ")") {
slash = false
@ -319,12 +328,16 @@ func fixLogModule(fixed string) string {
if strings.Compare(l1, gitHubLogs) > 0 {
newFixed += fmt.Sprintf("\t" + `"github.com/astaxie/beego/logs"` + "\n")
inserted = true
continue
}
if strings.Compare(l1, gitHubLogs) < 0 && strings.Compare(l2, gitHubLogs) > 0 {
newFixed += fmt.Sprintf("\t" + `"github.com/astaxie/beego/logs"` + "\n")
inserted = true
continue
}
continue
}
startImport = strings.HasPrefix(line, "import")
}