This commit is contained in:
2025-02-18 20:56:33 +07:00
parent c1a21a5fa4
commit b406d68abb
3 changed files with 14 additions and 11 deletions

View File

@@ -21,7 +21,7 @@ func FindFrontendPath() string {
currentPath = filepath.Clean(dir) currentPath = filepath.Clean(dir)
} }
if len(dirs) < 2 || dirs[len(dirs)-2]+"/"+dirs[len(dirs)-1] != "frontend/src" { if len(dirs) < 2 || dirs[len(dirs)-2] + "/" + dirs[len(dirs)-1] != "frontend/src" {
panic(errors.New("You're not in frontend/src")) panic(errors.New("You're not in frontend/src"))
} }

View File

@@ -24,7 +24,10 @@ func GetStructFields(file *os.File, structName string) []entities.Field {
bracketsCount += strings.Count(line, "{") bracketsCount += strings.Count(line, "{")
bracketsCount -= strings.Count(line, "}") bracketsCount -= strings.Count(line, "}")
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
newField := SplitStructField(line) newField, err := SplitStructField(line)
if err != nil {
return structFields
}
if newField != nil { if newField != nil {
structFields = append(structFields, *newField) structFields = append(structFields, *newField)
} }
@@ -34,6 +37,5 @@ func GetStructFields(file *os.File, structName string) []entities.Field {
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
panic(err) panic(err)
} }
return structFields return structFields
} }

View File

@@ -1,15 +1,19 @@
package utils package utils
import ( import (
"errors"
"nto_cli/entities" "nto_cli/entities"
"strings" "strings"
"github.com/fatih/structtag" "github.com/fatih/structtag"
) )
func SplitStructField(field string) *entities.Field { func SplitStructField(field string) (*entities.Field, error) {
if strings.Contains(field, "type") { if strings.Contains(field, "type") {
return nil return nil, nil
}
if len(strings.TrimSpace(field)) < 2 {
return nil, errors.New("End")
} }
startBacktip := strings.Index(field, "`") startBacktip := strings.Index(field, "`")
endBacktip := -1 endBacktip := -1
@@ -42,9 +46,6 @@ func SplitStructField(field string) *entities.Field {
data := SplitBySingleSpace(field) data := SplitBySingleSpace(field)
if len(data) < 2 {
return nil
}
name := data[0] name := data[0]
dataType := data[1] dataType := data[1]
@@ -52,5 +53,5 @@ func SplitStructField(field string) *entities.Field {
Medatada: metadata, Medatada: metadata,
Type: dataType, Type: dataType,
Name: name, Name: name,
} }, nil
} }