1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 10:10:53 +00:00

Merge pull request #692 from beego/feature/beegopro

repair staticcheck
This commit is contained in:
askuy 2020-07-21 22:27:25 +08:00 committed by GitHub
commit 13a81b8140
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 47 deletions

View File

@ -21,32 +21,33 @@ var DefaultBeegoPro = &Container{
TimestampFile: system.CurrentDir + "/.beegopro.timestamp", TimestampFile: system.CurrentDir + "/.beegopro.timestamp",
GoModFile: system.CurrentDir + "/go.mod", GoModFile: system.CurrentDir + "/go.mod",
UserOption: UserOption{ UserOption: UserOption{
Debug: false, Debug: false,
ContextDebug: false, ContextDebug: false,
Dsn: "", Dsn: "",
Driver: "mysql", Driver: "mysql",
ProType: "default", ProType: "default",
ApiPrefix: "/api", ApiPrefix: "/api",
EnableModule: nil, EnableModule: nil,
Models: make(map[string]TextModel, 0), Models: make(map[string]TextModel),
GitRemotePath: "https://github.com/beego/beego-pro.git", GitRemotePath: "https://github.com/beego/beego-pro.git",
Branch: "master", Branch: "master",
GitLocalPath: system.BeegoHome + "/beego-pro", GitLocalPath: system.BeegoHome + "/beego-pro",
EnableFormat: true, EnableFormat: true,
SourceGen: "text", SourceGen: "text",
EnableGitPull: true, EnableGitPull: true,
RefreshGitTime: 24 * 3600,
Path: map[string]string{ Path: map[string]string{
"beego": ".", "beego": ".",
}, },
EnableGomod: true, EnableGomod: true,
RefreshGitTime: 24 * 3600,
Extend: nil,
}, },
GenerateTime: time.Now().Format(MDateFormat), GenerateTime: time.Now().Format(MDateFormat),
GenerateTimeUnix: time.Now().Unix(), GenerateTimeUnix: time.Now().Unix(),
TmplOption: TmplOption{}, TmplOption: TmplOption{},
CurPath: system.CurrentDir, CurPath: system.CurrentDir,
EnableModules: make(map[string]interface{}, 0), // get the user configuration, get the enable module result EnableModules: make(map[string]interface{}), // get the user configuration, get the enable module result
FunctionOnce: make(map[string]sync.Once, 0), // get the tmpl configuration, get the function once result FunctionOnce: make(map[string]sync.Once), // get the tmpl configuration, get the function once result
} }
func (c *Container) Run() { func (c *Container) Run() {
@ -128,7 +129,7 @@ func (c *Container) initTemplateOption() {
} }
for _, value := range c.TmplOption.Descriptor { for _, value := range c.TmplOption.Descriptor {
if value.Once == true { if value.Once {
c.FunctionOnce[value.SrcName] = sync.Once{} c.FunctionOnce[value.SrcName] = sync.Once{}
} }
} }

View File

@ -10,7 +10,6 @@ import (
type MysqlParser struct { type MysqlParser struct {
userOption UserOption userOption UserOption
tmplOption TmplOption tmplOption TmplOption
db *sql.DB
} }
func (m *MysqlParser) RegisterOption(userOption UserOption, tmplOption TmplOption) { func (m *MysqlParser) RegisterOption(userOption UserOption, tmplOption TmplOption) {

View File

@ -49,9 +49,9 @@ func pongo2CamelString(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *p
return pongo2.AsValue(utils.CamelString(t)), nil return pongo2.AsValue(utils.CamelString(t)), nil
} }
func upperFirst(str string) string { //func upperFirst(str string) string {
return strings.Replace(str, string(str[0]), strings.ToUpper(string(str[0])), 1) // return strings.Replace(str, string(str[0]), strings.ToUpper(string(str[0])), 1)
} //}
func lowerFirst(str string) string { func lowerFirst(str string) string {
return strings.Replace(str, string(str[0]), strings.ToLower(string(str[0])), 1) return strings.Replace(str, string(str[0]), strings.ToLower(string(str[0])), 1)

View File

@ -34,7 +34,7 @@ func NewRender(m RenderInfo) *RenderFile {
newDescriptor, pathCtx = m.Descriptor.Parse(m.ModelName, m.Option.Path) newDescriptor, pathCtx = m.Descriptor.Parse(m.ModelName, m.Option.Path)
obj := &RenderFile{ obj := &RenderFile{
Context: make(pongo2.Context, 0), Context: make(pongo2.Context),
Option: m.Option, Option: m.Option,
ModelName: m.ModelName, ModelName: m.ModelName,
GenerateTime: m.GenerateTime, GenerateTime: m.GenerateTime,
@ -61,7 +61,7 @@ func NewRender(m RenderInfo) *RenderFile {
modelSchemas := m.Content.ToModelSchemas() modelSchemas := m.Content.ToModelSchemas()
camelPrimaryKey := modelSchemas.GetPrimaryKey() camelPrimaryKey := modelSchemas.GetPrimaryKey()
importMaps := make(map[string]struct{}, 0) importMaps := make(map[string]struct{})
if modelSchemas.IsExistTime() { if modelSchemas.IsExistTime() {
importMaps["time"] = struct{}{} importMaps["time"] = struct{}{}
} }

View File

@ -75,7 +75,7 @@ func (descriptor Descriptor) Parse(modelName string, paths map[string]string) (n
newDescriptor = descriptor newDescriptor = descriptor
render := pongo2render.NewRender("") render := pongo2render.NewRender("")
ctx = make(pongo2.Context, 0) ctx = make(pongo2.Context)
for key, value := range paths { for key, value := range paths {
absFile, err = filepath.Abs(value) absFile, err = filepath.Abs(value)
if err != nil { if err != nil {
@ -110,10 +110,7 @@ func (descriptor Descriptor) Parse(modelName string, paths map[string]string) (n
} }
func (descriptor Descriptor) IsExistScript() bool { func (descriptor Descriptor) IsExistScript() bool {
if descriptor.Script != "" { return descriptor.Script != ""
return true
}
return false
} }
func (d Descriptor) ExecScript(path string) (err error) { func (d Descriptor) ExecScript(path string) (err error) {

View File

@ -46,7 +46,12 @@ func (c *RenderFile) write(filename string, buf string) (err error) {
} }
file, err := os.Create(filename) file, err := os.Create(filename)
defer file.Close() defer func() {
err = file.Close()
if err != nil {
beeLogger.Log.Fatalf("file close error, err %s", err)
}
}()
if err != nil { if err != nil {
err = errors.New("write create file " + err.Error()) err = errors.New("write create file " + err.Error())
return return

View File

@ -206,19 +206,3 @@ func concatenateError(err error, stderr string) error {
} }
return fmt.Errorf("%v: %s", err, stderr) return fmt.Errorf("%v: %s", err, stderr)
} }
// getGitProjectName 获取项目名称
func getGitProjectName(url string) (name string, err error) {
if !strings.Contains(url, ".git") {
return "", errors.New("Project address does not contain .git")
}
fileSlice := strings.Split(url, "/")
projectName := fileSlice[len(fileSlice)-1]
if projectName == "" {
return "", errors.New("Project name does not exist")
}
nameSlice := strings.Split(projectName, ".git")
return nameSlice[0], nil
}