mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 19:40:34 +07:00
feat: getting struct fields
This commit is contained in:
38
utils/split_struct_field.go
Normal file
38
utils/split_struct_field.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"nto_cli/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SplitStructField(field string) *types.Field {
|
||||
if strings.Contains(field, "type") {
|
||||
return nil
|
||||
}
|
||||
|
||||
startBacktip := strings.Index(field, "`")
|
||||
var metadata []string
|
||||
if startBacktip > -1 {
|
||||
metadata = []string{field[startBacktip:]}
|
||||
} else {
|
||||
startBacktip = len(field)
|
||||
}
|
||||
|
||||
field = strings.TrimSpace(field[:startBacktip])
|
||||
|
||||
data := strings.Split(field, " ")
|
||||
|
||||
if len(data) < 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(data[0])
|
||||
|
||||
dataType := strings.TrimSpace(data[1])
|
||||
|
||||
return &types.Field{
|
||||
Medatada: metadata,
|
||||
Type: dataType,
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user