Browse Source

repair staticcheck

feature/beegopro
yitea 1 year ago
parent
commit
d9633cd9af
  1. 39
      internal/app/module/beegopro/container.go
  2. 1
      internal/app/module/beegopro/parser_mysql.go
  3. 6
      internal/app/module/beegopro/pongo2.go
  4. 4
      internal/app/module/beegopro/render.go
  5. 7
      internal/app/module/beegopro/schema.go
  6. 7
      internal/app/module/beegopro/util.go
  7. 16
      internal/pkg/git/repository.go

39
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{}
}
}

1
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) {

6
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)

4
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{}{}
}

7
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) {

7
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

16
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
}

Loading…
Cancel
Save