feature model interface (#222)

* make variable declaration more concise

* add model interface

* optimize interface methods

* fix: go test failed

* warp returns

* optimize
This commit is contained in:
Keson
2020-11-24 22:36:23 +08:00
committed by GitHub
parent b9ac51b6c3
commit 6e57f6c527
21 changed files with 414 additions and 232 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
)
func genInsert(table Table, withCache bool) (string, error) {
func genInsert(table Table, withCache bool) (string, string, error) {
keySet := collection.NewSet()
keyVariableSet := collection.NewSet()
for fieldName, key := range table.CacheKey {
@@ -36,7 +36,7 @@ func genInsert(table Table, withCache bool) (string, error) {
camel := table.Name.ToCamel()
text, err := util.LoadTemplate(category, insertTemplateFile, template.Insert)
if err != nil {
return "", err
return "", "", err
}
output, err := util.With("insert").
@@ -52,8 +52,23 @@ func genInsert(table Table, withCache bool) (string, error) {
"keyValues": strings.Join(keyVariableSet.KeysStr(), ", "),
})
if err != nil {
return "", err
return "", "", err
}
return output.String(), nil
// interface method
text, err = util.LoadTemplate(category, insertTemplateMethodFile, template.InsertMethod)
if err != nil {
return "", "", err
}
insertMethodOutput, err := util.With("insertMethod").
Parse(text).
Execute(map[string]interface{}{
"upperStartCamelObject": camel,
})
if err != nil {
return "", "", err
}
return output.String(), insertMethodOutput.String(), nil
}