From d9633cd9af4f8cbfaebff899911f3c4edb949746 Mon Sep 17 00:00:00 2001 From: yitea Date: Tue, 21 Jul 2020 22:24:42 +0800 Subject: [PATCH] repair staticcheck --- internal/app/module/beegopro/container.go | 39 ++++++++++---------- internal/app/module/beegopro/parser_mysql.go | 1 - internal/app/module/beegopro/pongo2.go | 6 +-- internal/app/module/beegopro/render.go | 4 +- internal/app/module/beegopro/schema.go | 7 +--- internal/app/module/beegopro/util.go | 7 +++- internal/pkg/git/repository.go | 16 -------- 7 files changed, 33 insertions(+), 47 deletions(-) diff --git a/internal/app/module/beegopro/container.go b/internal/app/module/beegopro/container.go index 296033b..3046698 100644 --- a/internal/app/module/beegopro/container.go +++ b/internal/app/module/beegopro/container.go @@ -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{} } } diff --git a/internal/app/module/beegopro/parser_mysql.go b/internal/app/module/beegopro/parser_mysql.go index 204c704..08180cc 100644 --- a/internal/app/module/beegopro/parser_mysql.go +++ b/internal/app/module/beegopro/parser_mysql.go @@ -10,7 +10,6 @@ import ( type MysqlParser struct { userOption UserOption tmplOption TmplOption - db *sql.DB } func (m *MysqlParser) RegisterOption(userOption UserOption, tmplOption TmplOption) { diff --git a/internal/app/module/beegopro/pongo2.go b/internal/app/module/beegopro/pongo2.go index 3304230..31453c6 100644 --- a/internal/app/module/beegopro/pongo2.go +++ b/internal/app/module/beegopro/pongo2.go @@ -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) diff --git a/internal/app/module/beegopro/render.go b/internal/app/module/beegopro/render.go index ba5d2b7..f2e49c3 100644 --- a/internal/app/module/beegopro/render.go +++ b/internal/app/module/beegopro/render.go @@ -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{}{} } diff --git a/internal/app/module/beegopro/schema.go b/internal/app/module/beegopro/schema.go index f29d981..c4f6a1e 100644 --- a/internal/app/module/beegopro/schema.go +++ b/internal/app/module/beegopro/schema.go @@ -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) { diff --git a/internal/app/module/beegopro/util.go b/internal/app/module/beegopro/util.go index 79f02a3..646ffb2 100644 --- a/internal/app/module/beegopro/util.go +++ b/internal/app/module/beegopro/util.go @@ -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 diff --git a/internal/pkg/git/repository.go b/internal/pkg/git/repository.go index d32d597..d24a840 100644 --- a/internal/pkg/git/repository.go +++ b/internal/pkg/git/repository.go @@ -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 -}