forked from vetcher/go-astra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
45 lines (37 loc) · 900 Bytes
/
struct.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package types
import (
"fmt"
"strings"
)
type StructField struct {
Variable
Tags map[string][]string `json:"tags,omitempty"`
RawTags string `json:"raw,omitempty"` // Raw string from source.
}
func (f StructField) String() string {
return fmt.Sprintf("%s `%s`", f.Variable.String(), f.RawTags)
}
type Struct struct {
Base
Fields []StructField `json:"fields,omitempty"`
Methods []*Method `json:"methods,omitempty"`
}
func (s Struct) t() { return }
func stringFields(fields []StructField) string {
var str strings.Builder
if len(fields) == 0 {
return ""
}
for i := range fields {
str.WriteString("\n")
str.WriteString(fields[i].String())
}
str.WriteString("\n")
return str.String()
}
func (s Struct) String() string {
return fmt.Sprintf("%s struct {%s}", s.Name, stringFields(s.Fields))
}
func (s Struct) IsEmpty() bool {
return len(s.Fields) == 0
}