-
Notifications
You must be signed in to change notification settings - Fork 583
/
overrides.go
50 lines (41 loc) · 1.1 KB
/
overrides.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
// SPDX-License-Identifier: AGPL-3.0-only
package fieldcategory
import "fmt"
type Category int
const (
// Basic is the basic field category, and the default if none is defined.
Basic Category = iota
// Advanced is the advanced field category.
Advanced
// Experimental is the experimental field category.
Experimental
)
func (c Category) String() string {
switch c {
case Basic:
return "basic"
case Advanced:
return "advanced"
case Experimental:
return "experimental"
default:
panic(fmt.Sprintf("Unknown field category: %d", c))
}
}
// Fields are primarily categorized via struct tags, but this can be impossible when third party libraries are involved
// Only categorize fields here when you can't otherwise, since struct tags are less likely to become stale
var overrides = map[string]Category{}
func AddOverrides(o map[string]Category) {
for n, c := range o {
overrides[n] = c
}
}
func GetOverride(fieldName string) (category Category, ok bool) {
category, ok = overrides[fieldName]
return
}
func VisitOverrides(f func(name string)) {
for override := range overrides {
f(override)
}
}