1
0
mirror of https://github.com/beego/bee.git synced 2025-07-01 17:20:17 +00:00

fix api hprose project

This commit is contained in:
qiantao
2020-05-26 17:58:56 +08:00
parent 8ebc0adfd1
commit 0163d03646
5 changed files with 147 additions and 24 deletions

View File

@ -15,15 +15,17 @@
package generate
import (
"bufio"
"database/sql"
"fmt"
"io"
"os"
"path"
"path/filepath"
"regexp"
"strings"
beeLogger "github.com/beego/bee/logger"
"github.com/beego/bee/logger"
"github.com/beego/bee/logger/colors"
"github.com/beego/bee/utils"
_ "github.com/go-sql-driver/mysql"
@ -946,6 +948,37 @@ func getFileName(tbName string) (filename string) {
}
func getPackagePath(curpath string) (packpath string) {
if os.Getenv(`GO111MODULE`) == `on` {
beeLogger.Log.Infof("GO111MODULE = on,curpath: %s", curpath)
gomodpath := filepath.Join(curpath, `go.mod`)
re, err := regexp.Compile(`^module\s+(.+)$`)
if err != nil {
beeLogger.Log.Fatalf("generate regexp error:%s", err)
return ""
}
fd, err := os.Open(gomodpath)
if err != nil {
beeLogger.Log.Fatalf("Error while reading 'go.mod',%s", gomodpath)
}
reader := bufio.NewReader(fd)
for {
byteLine, _, er := reader.ReadLine()
if er != nil && er != io.EOF {
return ""
}
if er == io.EOF {
break
}
line := string(byteLine)
s := re.FindStringSubmatch(line)
if len(s) >= 2 {
return s[1]
}
}
beeLogger.Log.Fatalf("Error while parse 'go.mod',%s", gomodpath)
return ""
}
gopath := os.Getenv("GOPATH")
if gopath == "" {
beeLogger.Log.Fatal("GOPATH environment variable is not set or empty")