mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 18:20:34 +07:00
fix: a few bugs
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Field struct {
|
type Field struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
@@ -21,37 +20,37 @@ func (f *Field) GenerateType() string {
|
|||||||
if slices.Contains(PRIMITIVE_TYPES, strings.ToLower(f.Type)) {
|
if slices.Contains(PRIMITIVE_TYPES, strings.ToLower(f.Type)) {
|
||||||
result += fmt.Sprintf(` primitive: "%s",`, strings.ToLower(f.Type))
|
result += fmt.Sprintf(` primitive: "%s",`, strings.ToLower(f.Type))
|
||||||
} else {
|
} else {
|
||||||
var field string
|
var field string = "[]"
|
||||||
for _, meta := range f.Medatada {
|
for _, meta := range f.Medatada {
|
||||||
if meta.Name == "field" {
|
if meta.Name == "field" {
|
||||||
field = "['" + strings.Join(meta.Values, "', '") + "']"
|
if len(meta.Values) > 0 {
|
||||||
|
field = "['" + strings.Join(meta.Values, "', '") + "']"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result += fmt.Sprintf(` nested: {
|
result += fmt.Sprintf(` nested: {
|
||||||
values: [],
|
values: [],
|
||||||
field: %s
|
field: %s
|
||||||
}, `, field)
|
}, `, field)
|
||||||
}
|
|
||||||
result += "\n }"
|
|
||||||
for _, meta := range f.Medatada {
|
|
||||||
if meta.Name == "many" {
|
|
||||||
result += "\n many: true }"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
result += "\n },"
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Field) Generate() string {
|
func (f *Field) Generate() string {
|
||||||
result := "{\n"
|
result := "{\n"
|
||||||
for _, meta := range f.Medatada {
|
for _, meta := range f.Medatada {
|
||||||
if (meta.Name == "hidden") {
|
if meta.Name == "hidden" {
|
||||||
result += " hidden: true,\n"
|
result += " hidden: true,\n"
|
||||||
} else if meta.Name == "label" {
|
} else if meta.Name == "label" {
|
||||||
result += fmt.Sprintf(` russian: "%s",` + "\n", meta.Values[0])
|
result += fmt.Sprintf(` russian: "%s",`+"\n", meta.Values[0])
|
||||||
} else if (meta.Name == "readonly") {
|
} else if meta.Name == "readonly" {
|
||||||
result += " readonly: true,\n"
|
result += " readonly: true,\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if f.Type[0:2] == "[]" {
|
||||||
|
result += " many: true,\n"
|
||||||
|
}
|
||||||
result += f.GenerateType()
|
result += f.GenerateType()
|
||||||
return result + "\n}"
|
return result + "\n}"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package entities
|
package entities
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type Medatada struct {
|
type Medatada struct {
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ func SplitStructField(field string) *entities.Field {
|
|||||||
startBacktip = len(field)
|
startBacktip = len(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
field = strings.TrimSpace(field[:startBacktip])
|
field = strings.TrimSpace(field[:startBacktip])
|
||||||
|
|
||||||
data := strings.Split(field, " ")
|
data := strings.Split(field, " ")
|
||||||
|
|||||||
Reference in New Issue
Block a user