mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 20:20:34 +07:00
42 lines
826 B
Go
42 lines
826 B
Go
package utils
|
|
|
|
import (
|
|
"bufio"
|
|
"nto_cli/entities"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func GetStructFields(file *os.File, structName string) []entities.Field {
|
|
bracketsCount := 1
|
|
|
|
structFound := false
|
|
|
|
structFields := []entities.Field{}
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
for i := 1; scanner.Scan() && bracketsCount > 0; i++ {
|
|
line := scanner.Text()
|
|
if ContainsMany(line, structName, "type", "struct") {
|
|
structFound = true
|
|
}
|
|
if structFound {
|
|
bracketsCount += strings.Count(line, "{")
|
|
bracketsCount -= strings.Count(line, "}")
|
|
line = strings.TrimSpace(line)
|
|
newField, err := SplitStructField(line)
|
|
if err != nil {
|
|
return structFields
|
|
}
|
|
if newField != nil {
|
|
structFields = append(structFields, *newField)
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
panic(err)
|
|
}
|
|
return structFields
|
|
}
|