You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/tools/goctl/model/mongomodel/gen/genmethod.go

34 lines
707 B
Go

4 years ago
package gen
import (
"strings"
"zero/tools/goctl/model/mongomodel/utils"
)
func genMethodTemplate(funcDesc FunctionDesc, needCache bool) (template string) {
var tmp string
switch funcDesc.Type {
case functionTypeGet:
if needCache {
tmp = getTemplate
} else {
tmp = noCacheGetTemplate
}
case functionTypeFind:
tmp = findTemplate
case functionTypeSet:
if needCache {
tmp = ""
} else {
tmp = noCacheSetFieldtemplate
}
default:
return ""
}
tmp = strings.ReplaceAll(tmp, "{{.Name}}", funcDesc.FieldName)
tmp = strings.ReplaceAll(tmp, "{{.name}}", utils.UpperCamelToLower(funcDesc.FieldName))
tmp = strings.ReplaceAll(tmp, "{{.type}}", funcDesc.FieldType)
return tmp
}