mirror of
				https://github.com/beego/bee.git
				synced 2025-10-30 10:43:22 +00:00 
			
		
		
		
	Merge branch 'develop' into fix-required-tag
This commit is contained in:
		| @@ -14,7 +14,7 @@ | ||||
|  | ||||
| package generate | ||||
|  | ||||
| import "github.com/beego/bee/utils" | ||||
| import "github.com/beego/bee/v2/utils" | ||||
|  | ||||
| var SQLDriver utils.DocValue | ||||
| var SQLConn utils.DocValue | ||||
|   | ||||
| @@ -15,17 +15,19 @@ | ||||
| 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/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| 	_ "github.com/go-sql-driver/mysql" | ||||
| 	_ "github.com/lib/pq" | ||||
| ) | ||||
| @@ -923,9 +925,9 @@ func extractColSize(colType string) string { | ||||
| } | ||||
|  | ||||
| func extractIntSignness(colType string) string { | ||||
| 	regex := regexp.MustCompile(`(int|smallint|mediumint|bigint)\([0-9]+\)(.*)`) | ||||
| 	regex := regexp.MustCompile(`(int|smallint|mediumint|bigint).*`) | ||||
| 	signRegex := regex.FindStringSubmatch(colType) | ||||
| 	return strings.Trim(signRegex[2], " ") | ||||
| 	return strings.Trim(signRegex[1], " ") | ||||
| } | ||||
|  | ||||
| func extractDecimal(colType string) (digits string, decimals string) { | ||||
| @@ -948,11 +950,40 @@ func getFileName(tbName string) (filename string) { | ||||
| func getPackagePath(curpath string) (packpath string) { | ||||
| 	gopath := os.Getenv("GOPATH") | ||||
| 	if gopath == "" { | ||||
| 		beeLogger.Log.Fatal("GOPATH environment variable is not set or empty") | ||||
| 		info := "GOPATH environment variable is not set or empty" | ||||
| 		gomodpath := filepath.Join(curpath, `go.mod`) | ||||
| 		re, err := regexp.Compile(`^module\s+(.+)$`) | ||||
| 		if err != nil { | ||||
| 			beeLogger.Log.Error(info) | ||||
| 			beeLogger.Log.Fatalf("try `go.mod` generate regexp error:%s", err) | ||||
| 			return "" | ||||
| 		} | ||||
| 		fd, err := os.Open(gomodpath) | ||||
| 		if err != nil { | ||||
| 			beeLogger.Log.Error(info) | ||||
| 			beeLogger.Log.Fatalf("try `go.mod`  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.Error(info) | ||||
| 		beeLogger.Log.Fatalf("try `go.mod` Error while parse 'go.mod',%s", gomodpath) | ||||
| 	} else { | ||||
| 		beeLogger.Log.Debugf("GOPATH: %s", utils.FILE(), utils.LINE(), gopath) | ||||
| 	} | ||||
|  | ||||
| 	beeLogger.Log.Debugf("GOPATH: %s", utils.FILE(), utils.LINE(), gopath) | ||||
|  | ||||
| 	appsrcpath := "" | ||||
| 	haspath := false | ||||
| 	wgopath := filepath.SplitList(gopath) | ||||
| @@ -992,7 +1023,7 @@ import ( | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	{{timePkg}} | ||||
| 	"github.com/astaxie/beego/orm" | ||||
| 	"github.com/beego/beego/v2/client/orm" | ||||
| ) | ||||
|  | ||||
| {{modelStruct}} | ||||
| @@ -1141,7 +1172,7 @@ import ( | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/astaxie/beego" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
|  | ||||
| // {{ctrlName}}Controller operations for {{ctrlName}} | ||||
| @@ -1316,7 +1347,7 @@ package routers | ||||
| import ( | ||||
| 	"{{pkgPath}}/controllers" | ||||
|  | ||||
| 	"github.com/astaxie/beego" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
|   | ||||
| @@ -20,9 +20,9 @@ import ( | ||||
| 	"path" | ||||
| 	"strings" | ||||
|  | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/logger/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| ) | ||||
|  | ||||
| func GenerateController(cname, currpath string) { | ||||
| @@ -78,7 +78,7 @@ func GenerateController(cname, currpath string) { | ||||
| var controllerTpl = `package {{packageName}} | ||||
|  | ||||
| import ( | ||||
| 	"github.com/astaxie/beego" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
|  | ||||
| // {{controllerName}}Controller operations for {{controllerName}} | ||||
| @@ -166,7 +166,7 @@ import ( | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/astaxie/beego" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
|  | ||||
| //  {{controllerName}}Controller operations for {{controllerName}} | ||||
|   | ||||
| @@ -24,9 +24,9 @@ import ( | ||||
| 	"path" | ||||
| 	"strings" | ||||
|  | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/logger/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| 	_ "github.com/go-sql-driver/mysql" | ||||
| 	_ "github.com/lib/pq" | ||||
| ) | ||||
| @@ -47,7 +47,7 @@ import ( | ||||
| 	"{{.Appname}}/models" | ||||
| 	"github.com/hprose/hprose-golang/rpc" | ||||
|  | ||||
| 	"github.com/astaxie/beego" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
|  | ||||
| func logInvokeHandler( | ||||
| @@ -90,8 +90,8 @@ import ( | ||||
| 	"{{.Appname}}/models" | ||||
| 	"github.com/hprose/hprose-golang/rpc" | ||||
|  | ||||
| 	"github.com/astaxie/beego" | ||||
| 	"github.com/astaxie/beego/orm" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| 	"github.com/beego/beego/v2/client/orm" | ||||
| 	{{.DriverPkg}} | ||||
| ) | ||||
|  | ||||
| @@ -419,7 +419,7 @@ import ( | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	{{timePkg}} | ||||
| 	"github.com/astaxie/beego/orm" | ||||
| 	"github.com/beego/beego/v2/client/orm" | ||||
| ) | ||||
|  | ||||
| {{modelStruct}} | ||||
|   | ||||
| @@ -21,9 +21,9 @@ import ( | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/logger/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	"github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -238,7 +238,7 @@ func GenerateMigration(mname, upsql, downsql, curpath string) { | ||||
| const ( | ||||
| 	MigrationHeader = `package main | ||||
| 						import ( | ||||
| 							"github.com/astaxie/beego/migration" | ||||
| 							"github.com/beego/beego/v2/client/orm/migration" | ||||
| 						) | ||||
|  | ||||
| 						// DO NOT MODIFY | ||||
|   | ||||
| @@ -21,9 +21,9 @@ import ( | ||||
| 	"path" | ||||
| 	"strings" | ||||
|  | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/logger/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| ) | ||||
|  | ||||
| func GenerateModel(mname, fields, currpath string) { | ||||
| @@ -145,7 +145,7 @@ import ( | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	{{timePkg}} | ||||
| 	"github.com/astaxie/beego/orm" | ||||
| 	"github.com/beego/beego/v2/client/orm" | ||||
| ) | ||||
|  | ||||
| {{modelStruct}} | ||||
|   | ||||
| @@ -3,9 +3,9 @@ package generate | ||||
| import ( | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/beego/bee/cmd/commands/migrate" | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	"github.com/beego/bee/v2/cmd/commands/migrate" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| ) | ||||
|  | ||||
| func GenerateScaffold(sname, fields, currpath, driver, conn string) { | ||||
|   | ||||
| @@ -19,9 +19,9 @@ import ( | ||||
| 	"os" | ||||
| 	"path" | ||||
|  | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	"github.com/beego/bee/logger/colors" | ||||
| 	"github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/bee/v2/logger/colors" | ||||
| 	"github.com/beego/bee/v2/utils" | ||||
| ) | ||||
|  | ||||
| // recipe | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"go/ast" | ||||
| 	"go/build" | ||||
| 	"go/parser" | ||||
| 	"go/token" | ||||
| 	"os" | ||||
| @@ -34,10 +35,9 @@ import ( | ||||
|  | ||||
| 	yaml "gopkg.in/yaml.v2" | ||||
|  | ||||
| 	"github.com/astaxie/beego/swagger" | ||||
| 	"github.com/astaxie/beego/utils" | ||||
| 	beeLogger "github.com/beego/bee/logger" | ||||
| 	bu "github.com/beego/bee/utils" | ||||
| 	beeLogger "github.com/beego/bee/v2/logger" | ||||
| 	"github.com/beego/beego/v2/core/utils" | ||||
| 	"github.com/beego/beego/v2/server/web/swagger" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -102,8 +102,8 @@ func init() { | ||||
| 	astPkgs = make([]*ast.Package, 0) | ||||
| } | ||||
|  | ||||
| // ParsePackagesFromDir parses packages from a given directory | ||||
| func ParsePackagesFromDir(dirpath string) { | ||||
| // parsePackagesFromDir parses packages from a given directory | ||||
| func parsePackagesFromDir(dirpath string) { | ||||
| 	c := make(chan error) | ||||
|  | ||||
| 	go func() { | ||||
| @@ -157,8 +157,14 @@ func parsePackageFromDir(path string) error { | ||||
|  | ||||
| // GenerateDocs generates documentations for a given path. | ||||
| 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) | ||||
| 	if err != nil { | ||||
| 		beeLogger.Log.Fatalf("Error while parsing router.go: %s", err) | ||||
| @@ -263,7 +269,7 @@ func GenerateDocs(curpath string) { | ||||
| 		if im.Name != nil { | ||||
| 			localName = im.Name.Name | ||||
| 		} | ||||
| 		analyseControllerPkg(path.Join(curpath, "vendor"), localName, im.Path.Value) | ||||
| 		analyseControllerPkg(localName, im.Path.Value) | ||||
| 	} | ||||
| 	for _, d := range f.Decls { | ||||
| 		switch specDecl := d.(type) { | ||||
| @@ -418,12 +424,12 @@ func analyseNSInclude(baseurl string, ce *ast.CallExpr) string { | ||||
| 	return cname | ||||
| } | ||||
|  | ||||
| func analyseControllerPkg(vendorPath, localName, pkgpath string) { | ||||
| func analyseControllerPkg(localName, pkgpath string) { | ||||
| 	pkgpath = strings.Trim(pkgpath, "\"") | ||||
| 	if isSystemPackage(pkgpath) { | ||||
| 		return | ||||
| 	} | ||||
| 	if pkgpath == "github.com/astaxie/beego" { | ||||
| 	if pkgpath == "github.com/beego/beego/v2/server/web" { | ||||
| 		return | ||||
| 	} | ||||
| 	if localName != "" { | ||||
| @@ -432,32 +438,19 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { | ||||
| 		pps := strings.Split(pkgpath, "/") | ||||
| 		importlist[pps[len(pps)-1]] = pkgpath | ||||
| 	} | ||||
| 	gopaths := bu.GetGOPATHs() | ||||
| 	if len(gopaths) == 0 { | ||||
| 		beeLogger.Log.Fatal("GOPATH environment variable is not set or empty") | ||||
| 	} | ||||
| 	pkgRealpath := "" | ||||
|  | ||||
| 	wg, _ := filepath.EvalSymlinks(filepath.Join(vendorPath, pkgpath)) | ||||
| 	if utils.FileExists(wg) { | ||||
| 		pkgRealpath = wg | ||||
| 	} else { | ||||
| 		wgopath := gopaths | ||||
| 		for _, wg := range wgopath { | ||||
| 			wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath)) | ||||
| 			if utils.FileExists(wg) { | ||||
| 				pkgRealpath = wg | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	pkg, err := build.Default.Import(pkgpath, ".", build.FindOnly) | ||||
| 	if err != nil { | ||||
| 		beeLogger.Log.Fatalf("Package %s cannot be imported: %v", pkgpath, err) | ||||
| 	} | ||||
| 	pkgRealpath := pkg.Dir | ||||
| 	if pkgRealpath != "" { | ||||
| 		if _, ok := pkgCache[pkgpath]; ok { | ||||
| 			return | ||||
| 		} | ||||
| 		pkgCache[pkgpath] = struct{}{} | ||||
| 	} else { | ||||
| 		beeLogger.Log.Fatalf("Package '%s' does not exist in the GOPATH or vendor path", pkgpath) | ||||
| 		beeLogger.Log.Fatalf("Package '%s' does not have source directory", pkgpath) | ||||
| 	} | ||||
|  | ||||
| 	fileSet := token.NewFileSet() | ||||
| @@ -468,6 +461,7 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { | ||||
| 	if err != nil { | ||||
| 		beeLogger.Log.Fatalf("Error while parsing dir at '%s': %s", pkgpath, err) | ||||
| 	} | ||||
|  | ||||
| 	for _, pkg := range astPkgs { | ||||
| 		for _, fl := range pkg.Files { | ||||
| 			for _, d := range fl.Decls { | ||||
| @@ -730,7 +724,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	routerPath = urlReplace(routerPath) | ||||
| 	if routerPath != "" { | ||||
| 		//Go over function parameters which were not mapped and create swagger params for them | ||||
| 		for name, typ := range funcParamMap { | ||||
| @@ -802,7 +796,7 @@ func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName s | ||||
| 		paraFormat = typeFormat[1] | ||||
| 		if para.In == "body" { | ||||
| 			para.Schema = &swagger.Schema{ | ||||
| 				Type: paraType, | ||||
| 				Type:   paraType, | ||||
| 				Format: paraFormat, | ||||
| 			} | ||||
| 		} | ||||
| @@ -1209,7 +1203,7 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s | ||||
| 					for _, pkg := range astPkgs { | ||||
| 						for _, fl := range pkg.Files { | ||||
| 							for nameOfObj, obj := range fl.Scope.Objects { | ||||
| 								if obj.Name == fmt.Sprint(field.Type) { | ||||
| 								if pkg.Name+"."+obj.Name == realType { | ||||
| 									parseObject(obj, nameOfObj, nm, realTypes, astPkgs, pkg.Name) | ||||
| 								} | ||||
| 							} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 John
					John