mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 16:50:34 +07:00
meta parsing
This commit is contained in:
@@ -3,6 +3,7 @@ package input
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func Input() (string, string) {
|
func Input() (string, string) {
|
||||||
|
fmt.Print("struct name, path to file (including struct): ")
|
||||||
var structName, path string
|
var structName, path string
|
||||||
fmt.Scan(&structName, &path)
|
fmt.Scan(&structName, &path)
|
||||||
return structName, path
|
return structName, path
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package structs
|
package structs
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
title string `json sex`
|
title string `ui:",hidden,asd"`
|
||||||
}
|
}
|
||||||
2
go.mod
2
go.mod
@@ -1,3 +1,5 @@
|
|||||||
module nto_cli
|
module nto_cli
|
||||||
|
|
||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
|
require github.com/fatih/structtag v1.2.0 // indirect
|
||||||
|
|||||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
|
||||||
|
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
|
||||||
1
main.go
1
main.go
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Print("struct name, path to file (including struct): ")
|
|
||||||
structName, path := input.Input()
|
structName, path := input.Input()
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,5 +3,10 @@ package types
|
|||||||
type Field struct {
|
type Field struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
Medatada []string
|
Medatada []Medatada
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Medatada struct {
|
||||||
|
Name string
|
||||||
|
Values []string
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"nto_cli/types"
|
"nto_cli/types"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/structtag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SplitStructField(field string) *types.Field {
|
func SplitStructField(field string) *types.Field {
|
||||||
@@ -11,13 +14,28 @@ func SplitStructField(field string) *types.Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startBacktip := strings.Index(field, "`")
|
startBacktip := strings.Index(field, "`")
|
||||||
var metadata []string
|
endBacktip := -1
|
||||||
|
var metadata []types.Medatada
|
||||||
if startBacktip > -1 {
|
if startBacktip > -1 {
|
||||||
metadata = []string{field[startBacktip:]}
|
endBacktip = strings.Index(field[startBacktip + 1:], "`")
|
||||||
|
if endBacktip > -1 {
|
||||||
|
endBacktip += startBacktip + 1
|
||||||
|
meta := field[startBacktip + 1 : endBacktip]
|
||||||
|
tags, err := structtag.Parse(meta)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
uiTags, err := tags.Get("ui")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", uiTags.Options)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startBacktip = len(field)
|
startBacktip = len(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
field = strings.TrimSpace(field[:startBacktip])
|
field = strings.TrimSpace(field[:startBacktip])
|
||||||
|
|
||||||
data := strings.Split(field, " ")
|
data := strings.Split(field, " ")
|
||||||
|
|||||||
Reference in New Issue
Block a user