mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 18:00:24 +08:00
db16115037
* add execute files * add protoc-osx * add rpc generation * add rpc generation * add: rpc template generation * update usage * fixed env prepare for project in go path * optimize gomod cache * add README.md * format error * reactor templatex.go * remove waste code
42 lines
923 B
Go
42 lines
923 B
Go
package gen
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/parser"
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
)
|
|
|
|
func genFields(fields []parser.Field) (string, error) {
|
|
var list []string
|
|
for _, field := range fields {
|
|
result, err := genField(field)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
list = append(list, result)
|
|
}
|
|
return strings.Join(list, "\n"), nil
|
|
}
|
|
|
|
func genField(field parser.Field) (string, error) {
|
|
tag, err := genTag(field.Name.Source())
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
output, err := util.With("types").
|
|
Parse(template.Field).
|
|
Execute(map[string]interface{}{
|
|
"name": field.Name.ToCamel(),
|
|
"type": field.DataType,
|
|
"tag": tag,
|
|
"hasComment": field.Comment != "",
|
|
"comment": field.Comment,
|
|
})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return output.String(), nil
|
|
}
|