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:
@@ -6,11 +6,11 @@ import (
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
|
||||
)
|
||||
|
||||
func genFindOne(table Table, withCache bool) (string, error) {
|
||||
func genFindOne(table Table, withCache bool) (string, string, error) {
|
||||
camel := table.Name.ToCamel()
|
||||
text, err := util.LoadTemplate(category, findOneTemplateFile, template.FindOne)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
output, err := util.With("findOne").
|
||||
@@ -26,8 +26,23 @@ func genFindOne(table Table, withCache bool) (string, error) {
|
||||
"cacheKeyVariable": table.CacheKey[table.PrimaryKey.Name.Source()].Variable,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return output.String(), nil
|
||||
text, err = util.LoadTemplate(category, findOneMethodTemplateFile, template.FindOneMethod)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
findOneMethod, err := util.With("findOneMethod").
|
||||
Parse(text).
|
||||
Execute(map[string]interface{}{
|
||||
"upperStartCamelObject": camel,
|
||||
"lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(),
|
||||
"dataType": table.PrimaryKey.DataType,
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return output.String(), findOneMethod.String(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user