-
Notifications
You must be signed in to change notification settings - Fork 13
/
specs.go
81 lines (67 loc) · 1.42 KB
/
specs.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
package specs
import (
"fmt"
)
type maturity string
const (
wip maturity = "wip"
draft maturity = "draft"
reliable maturity = "reliable"
stable maturity = "stable"
permanent maturity = "permanent"
deprecated maturity = "deprecated"
)
func (m maturity) isMature() bool {
switch m {
case reliable, stable, permanent:
return true
default:
return false
}
}
type Spec string
const (
SubdomainGateway Spec = "subdomain-gateway"
DNSLinkResolver Spec = "dnslink-resolver"
IPNSResolver Spec = "ipns-resolver"
)
// All specs should be listed here.
var specMaturity = map[Spec]maturity{
SubdomainGateway: stable,
DNSLinkResolver: stable,
IPNSResolver: stable,
}
func (s Spec) IsMature() bool {
return specMaturity[s].isMature()
}
var specEnabled = map[Spec]bool{}
func (s Spec) IsEnabled() bool {
// If the spec was explicitly enabled or disabled, use that.
// Otherwise, use the maturity level.
if enabled, ok := specEnabled[s]; ok {
return enabled
} else {
return s.IsMature()
}
}
func (s Spec) Enable() {
specEnabled[s] = true
}
func (s Spec) Disable() {
specEnabled[s] = false
}
func All() []Spec {
specs := []Spec{}
for spec := range specMaturity {
specs = append(specs, spec)
}
return specs
}
func FromString(name string) (Spec, error) {
for _, spec := range All() {
if string(spec) == name {
return spec, nil
}
}
return "", fmt.Errorf("unknown spec: %s", name)
}