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)
}
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"))
}

View File

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

View File

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