MCPcopy Create free account
hub / github.com/davidschlachter/embedded-struct-visualizer / parseStruct

Function parseStruct

parser.go:65–102  ·  view source on GitHub ↗
(scanner *bufio.Scanner, line string, pkg string, path string)

Source from the content-addressed store, hash-verified

63}
64
65func parseStruct(scanner *bufio.Scanner, line string, pkg string, path string) {
66 name := getName(line)
67 s := Struct{
68 Name: name,
69 Package: pkg,
70 FilePath: path,
71 Embeds: make(map[string]bool),
72 }
73 // Read the fields of this struct
74 for scanner.Scan() {
75 structLine := removeComments(scanner, scanner.Text())
76 log(structLine)
77 if structLine == "}" {
78 break
79 }
80 if structLine == "" {
81 continue
82 }
83 if strings.HasSuffix(structLine, " struct {") {
84 for scanner.Scan() {
85 if strings.TrimSpace(scanner.Text()) == "}," {
86 break
87 }
88 }
89 continue
90 }
91 fields, hasStructs := getStructs(structLine)
92 if hasStructs {
93 for _, f := range fields {
94 s.Embeds[f] = true
95 }
96 }
97 }
98
99 // Add to the list
100 log(fmt.Sprintf("%+v\n", s))
101 structsList = append(structsList, s)
102}
103
104func getStructs(s string) ([]string, bool) {
105 tokens := strings.Fields(cleanTags(s))

Callers 1

readFileFunction · 0.85

Calls 4

getNameFunction · 0.85
removeCommentsFunction · 0.85
logFunction · 0.85
getStructsFunction · 0.85

Tested by

no test coverage detected