mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 09:50:00 +08:00
(goctl): support nested struct (#4211)
This commit is contained in:
@@ -59,16 +59,59 @@ func genFile(c fileGenConfig) error {
|
||||
|
||||
func writeProperty(writer io.Writer, name, tag, comment string, tp spec.Type, indent int) error {
|
||||
util.WriteIndent(writer, indent)
|
||||
var err error
|
||||
var (
|
||||
err error
|
||||
isNestedStruct bool
|
||||
)
|
||||
structType, ok := tp.(spec.DefineStruct)
|
||||
if ok && structType.IsNestedStruct() {
|
||||
isNestedStruct = true
|
||||
}
|
||||
if len(comment) > 0 {
|
||||
comment = strings.TrimPrefix(comment, "//")
|
||||
comment = "//" + comment
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s %s\n", strings.Title(name), tp.Name(), tag, comment)
|
||||
} else {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s\n", strings.Title(name), tp.Name(), tag)
|
||||
}
|
||||
|
||||
return err
|
||||
if isNestedStruct {
|
||||
_, err = fmt.Fprintf(writer, "%s struct {\n", strings.Title(name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := writeMember(writer, structType.Members); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(writer, "} %s", tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(comment) > 0 {
|
||||
_, err = fmt.Fprintf(writer, " %s", comment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = fmt.Fprint(writer, "\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if len(comment) > 0 {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s %s\n", strings.Title(name), tp.Name(), tag, comment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_, err = fmt.Fprintf(writer, "%s %s %s\n", strings.Title(name), tp.Name(), tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAuths(api *spec.ApiSpec) []string {
|
||||
|
||||
Reference in New Issue
Block a user