mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
chore: refactor BuildTypes in tsgen. (#4266)
This commit is contained in:
@@ -14,13 +14,31 @@ import (
|
|||||||
//go:embed components.tpl
|
//go:embed components.tpl
|
||||||
var componentsTemplate string
|
var componentsTemplate string
|
||||||
|
|
||||||
|
// BuildTypes generates the typescript code for the types.
|
||||||
|
func BuildTypes(types []spec.Type) (string, error) {
|
||||||
|
var builder strings.Builder
|
||||||
|
first := true
|
||||||
|
for _, tp := range types {
|
||||||
|
if first {
|
||||||
|
first = false
|
||||||
|
} else {
|
||||||
|
builder.WriteString("\n")
|
||||||
|
}
|
||||||
|
if err := writeType(&builder, tp); err != nil {
|
||||||
|
return "", apiutil.WrapErr(err, "Type "+tp.Name()+" generate error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func genComponents(dir string, api *spec.ApiSpec) error {
|
func genComponents(dir string, api *spec.ApiSpec) error {
|
||||||
types := api.Types
|
types := api.Types
|
||||||
if len(types) == 0 {
|
if len(types) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := buildTypes(types)
|
val, err := BuildTypes(types)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -45,24 +63,3 @@ func genComponents(dir string, api *spec.ApiSpec) error {
|
|||||||
"componentTypes": val,
|
"componentTypes": val,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTypes(types []spec.Type) (string, error) {
|
|
||||||
var builder strings.Builder
|
|
||||||
first := true
|
|
||||||
for _, tp := range types {
|
|
||||||
if first {
|
|
||||||
first = false
|
|
||||||
} else {
|
|
||||||
builder.WriteString("\n")
|
|
||||||
}
|
|
||||||
if err := writeType(&builder, tp); err != nil {
|
|
||||||
return "", apiutil.WrapErr(err, "Type "+tp.Name()+" generate error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildTypes(types []spec.Type) (string, error) {
|
|
||||||
return buildTypes(types)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user