Browse Source

fix lint

pull/6/head
Lunny Xiao 5 months ago
parent
commit
5f576b4bbd
Signed by: lunny <xiaolunwen@gmail.com> GPG Key ID: C3B7C91B632F738A
3 changed files with 17 additions and 18 deletions
  1. +2
    -1
      .gitignore
  2. +14
    -17
      cmd/reverse.go
  3. +1
    -0
      cmd/reverse_test.go

+ 2
- 1
.gitignore View File

@@ -1 +1,2 @@
reverse
reverse
models/

+ 14
- 17
cmd/reverse.go View File

@@ -147,6 +147,17 @@ func newFuncs() template.FuncMap {
return m
}

func convertMapper(mapname string) core.IMapper {
switch mapname {
case "gonic":
return core.LintGonicMapper
case "same":
return core.SameMapper{}
default:
return core.SnakeMapper{}
}
}

func runReverse(source *ReverseSource, target *ReverseTarget) error {
orm, err := xorm.NewEngine(source.Database, source.ConnStr)
if err != nil {
@@ -197,23 +208,9 @@ func runReverse(source *ReverseSource, target *ReverseTarget) error {
target.ExtName = "." + target.ExtName
}

var tableMapper, colMapper core.IMapper
switch target.TableMapper {
case "gonic":
tableMapper = core.LintGonicMapper
case "same":
tableMapper = core.SameMapper{}
default:
tableMapper = core.SnakeMapper{}
}
switch target.ColumnMapper {
case "gonic":
colMapper = core.LintGonicMapper
case "same":
colMapper = core.SameMapper{}
default:
colMapper = core.SnakeMapper{}
}
var tableMapper = convertMapper(target.TableMapper)
var colMapper = convertMapper(target.ColumnMapper)

funcs["TableMapper"] = tableMapper.Table2Obj
funcs["ColumnMapper"] = colMapper.Table2Obj



+ 1
- 0
cmd/reverse_test.go View File

@@ -10,6 +10,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
_ "github.com/mattn/go-sqlite3"
)

var result = fmt.Sprintf(`package models


Loading…
Cancel
Save