repair staticcheck

This commit is contained in:
yitea 2020-07-21 22:24:42 +08:00
parent cc2b2d1054
commit d9633cd9af
7 changed files with 33 additions and 47 deletions

View File

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

View File

@ -10,7 +10,6 @@ import (
type MysqlParser struct {
userOption UserOption
tmplOption TmplOption
db *sql.DB
}
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
}
func upperFirst(str string) string {
return strings.Replace(str, string(str[0]), strings.ToUpper(string(str[0])), 1)
}
//func upperFirst(str string) string {
// return strings.Replace(str, string(str[0]), strings.ToUpper(string(str[0])), 1)
//}
func lowerFirst(str string) string {
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)
obj := &RenderFile{
Context: make(pongo2.Context, 0),
Context: make(pongo2.Context),
Option: m.Option,
ModelName: m.ModelName,
GenerateTime: m.GenerateTime,
@ -61,7 +61,7 @@ func NewRender(m RenderInfo) *RenderFile {
modelSchemas := m.Content.ToModelSchemas()
camelPrimaryKey := modelSchemas.GetPrimaryKey()
importMaps := make(map[string]struct{}, 0)
importMaps := make(map[string]struct{})
if modelSchemas.IsExistTime() {
importMaps["time"] = struct{}{}
}

View File

@ -75,7 +75,7 @@ func (descriptor Descriptor) Parse(modelName string, paths map[string]string) (n
newDescriptor = descriptor
render := pongo2render.NewRender("")
ctx = make(pongo2.Context, 0)
ctx = make(pongo2.Context)
for key, value := range paths {
absFile, err = filepath.Abs(value)
if err != nil {
@ -110,10 +110,7 @@ func (descriptor Descriptor) Parse(modelName string, paths map[string]string) (n
}
func (descriptor Descriptor) IsExistScript() bool {
if descriptor.Script != "" {
return true
}
return false
return descriptor.Script != ""
}
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)
defer file.Close()
defer func() {
err = file.Close()
if err != nil {
beeLogger.Log.Fatalf("file close error, err %s", err)
}
}()
if err != nil {
err = errors.New("write create file " + err.Error())
return

View File

@ -206,19 +206,3 @@ func concatenateError(err error, stderr string) error {
}
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
}