-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkers.go
102 lines (81 loc) · 2.58 KB
/
markers.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package markers
import (
"errors"
"strings"
)
// Reserved markers
const (
ImportMarkerName = "import"
DeprecatedMarkerName = "deprecated"
OverrideMarkerName = "override"
DefinitionMarkerName = "marker"
DefinitionParameterMarkerName = "marker:parameter"
DefinitionEnumMarkerName = "marker:enum"
)
var reservedMarkerMap = map[string]struct{}{
ImportMarkerName: {},
DeprecatedMarkerName: {},
OverrideMarkerName: {},
DefinitionMarkerName: {},
DefinitionParameterMarkerName: {},
DefinitionEnumMarkerName: {},
}
func IsReservedMarker(marker string) bool {
if _, exists := reservedMarkerMap[marker]; exists {
return true
}
return false
}
type ImportMarker struct {
Value string `parameter:"Value" required:"true"`
Alias string `parameter:"Alias" required:"false"`
Pkg string `parameter:"Pkg" required:"true"`
}
func (m ImportMarker) Validate() error {
var errs []error
if strings.Trim(m.Value, " \t") == "" {
errs = append(errs, errors.New("'Value' argument cannot be nil or empty"))
}
if strings.Trim(m.Pkg, " \t") == "" {
errs = append(errs, errors.New("'Pkg' argument cannot be nil or empty"))
}
if len(errs) != 0 {
return NewErrorList(errs)
}
return nil
}
func (m ImportMarker) PkgPath() string {
pkgParts := strings.Split(m.Pkg, "@")
return pkgParts[0]
}
func (m ImportMarker) PkgVersion() string {
pkgParts := strings.Split(m.Pkg, "@")
if len(pkgParts) > 1 {
return pkgParts[1]
}
return "latest"
}
type DeprecatedMarker struct {
Value string `parameter:"Value"`
}
type OverrideMarker struct {
Value string `parameter:"Value"`
}
type DefinitionMarker struct {
Value string `parameter:"Value" required:"true"`
Description string `parameter:"Description" required:"true"`
Repeatable bool `parameter:"Repeatable" required:"false"`
SyntaxFree bool `parameter:"SyntaxFree" required:"false"`
Targets []string `parameter:"Targets" required:"true" enum:"PACKAGE_LEVEL,STRUCT_TYPE_LEVEL,INTERFACE_TYPE_LEVEL,FIELD_LEVEL,FUNCTION_LEVEL,STRUCT_METHOD_LEVEL,INTERFACE_METHOD_LEVEL"`
}
type DefinitionParameterMarker struct {
Value string `parameter:"Value" required:"true"`
Description string `parameter:"Description" required:"true"`
Required bool `parameter:"Required" required:"false"`
Deprecated bool `parameter:"Deprecated" required:"false"`
Default any `parameter:"Default" required:"false"`
}
type DefinitionEnumMarker struct {
Value string `parameter:"Value" required:"true"`
Name string `parameter:"Name" required:"true"`
}