mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 16:30:33 +07:00
fix: paths, feat: many models, selection
This commit is contained in:
32
utils/get_structs_list.go
Normal file
32
utils/get_structs_list.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetStructList(filePath string) ([]string) {
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
var structNames []string
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
if strings.Contains(line, "type ") && strings.Contains(line, " struct") {
|
||||
start := strings.Index(line, "type ") + 5
|
||||
end := strings.Index(line, " struct")
|
||||
name := strings.TrimSpace(line[start:end])
|
||||
if name != "" {
|
||||
structNames = append(structNames, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return structNames
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func SplitStructField(field string) (*entities.Field, error) {
|
||||
if strings.Contains(field, "type") {
|
||||
if strings.Contains(field, "type") {
|
||||
return nil, nil
|
||||
}
|
||||
if len(strings.TrimSpace(field)) < 2 {
|
||||
@@ -19,23 +19,23 @@ func SplitStructField(field string) (*entities.Field, error) {
|
||||
endBacktip := -1
|
||||
var metadata []entities.Medatada
|
||||
if startBacktip > -1 {
|
||||
endBacktip = strings.Index(field[startBacktip + 1:], "`")
|
||||
endBacktip = strings.Index(field[startBacktip+1:], "`")
|
||||
if endBacktip > -1 {
|
||||
endBacktip += startBacktip + 1
|
||||
meta := field[startBacktip + 1 : endBacktip]
|
||||
meta := field[startBacktip+1 : endBacktip]
|
||||
tags, err := structtag.Parse(meta)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
uiTag, err := tags.Get("ui")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
uiTags := append([]string{uiTag.Name}, uiTag.Options...)
|
||||
for _, t := range uiTags {
|
||||
analyzed := entities.NewMetadata(t)
|
||||
if analyzed != nil {
|
||||
metadata = append(metadata, *analyzed)
|
||||
|
||||
if err == nil {
|
||||
uiTags := append([]string{uiTag.Name}, uiTag.Options...)
|
||||
for _, t := range uiTags {
|
||||
analyzed := entities.NewMetadata(t)
|
||||
if analyzed != nil {
|
||||
metadata = append(metadata, *analyzed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,11 @@ func SplitStructField(field string) (*entities.Field, error) {
|
||||
|
||||
data := SplitBySingleSpace(field)
|
||||
|
||||
|
||||
name := data[0]
|
||||
dataType := data[1]
|
||||
return &entities.Field{
|
||||
Medatada: metadata,
|
||||
Type: dataType,
|
||||
Name: name,
|
||||
Type: dataType,
|
||||
Name: name,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user