...
1
2
3
4 package ptr
5
6 import "strings"
7
8 func GetScalars() Scalars {
9 return Scalars{
10 {Type: "bool"},
11 {Type: "byte"},
12 {Type: "string"},
13 {Type: "int"},
14 {Type: "int8"},
15 {Type: "int16"},
16 {Type: "int32"},
17 {Type: "int64"},
18 {Type: "uint"},
19 {Type: "uint8"},
20 {Type: "uint16"},
21 {Type: "uint32"},
22 {Type: "uint64"},
23 {Type: "float32"},
24 {Type: "float64"},
25 {Type: "Time", Import: &Import{Path: "time"}},
26 {Type: "Duration", Import: &Import{Path: "time"}},
27 }
28 }
29
30
31 type Import struct {
32 Path string
33 Alias string
34 }
35
36
37 func (i Import) Package() string {
38 if v := i.Alias; len(v) != 0 {
39 return v
40 }
41
42 if v := i.Path; len(v) != 0 {
43 parts := strings.Split(v, "/")
44 pkg := parts[len(parts)-1]
45 return pkg
46 }
47
48 return ""
49 }
50
51
52 type Scalar struct {
53 Type string
54 Import *Import
55 }
56
57
58 func (t Scalar) Name() string {
59 return strings.Title(t.Type)
60 }
61
62
63 func (t Scalar) Symbol() string {
64 if t.Import != nil {
65 return t.Import.Package() + "." + t.Type
66 }
67 return t.Type
68 }
69
70
71 type Scalars []Scalar
72
73
74 func (ts Scalars) Imports() []*Import {
75 imports := []*Import{}
76 for _, t := range ts {
77 if v := t.Import; v != nil {
78 imports = append(imports, v)
79 }
80 }
81
82 return imports
83 }
84
View as plain text