generated from octomation/go-module
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature.go
58 lines (51 loc) · 1.23 KB
/
feature.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
package config
import (
"fmt"
"strings"
)
// Feature describe a feature.
type Feature struct {
ID [16]byte
Name string
Brief string
Docs string
RFC string
Enabled bool
}
// String returns a string representation of the feature.
func (feature Feature) String() string {
return fmt.Sprintf("%s=%v", feature.Name, feature.Enabled)
}
// Features defines a list of features.
type Features []Feature
// String returns a string representation of the feature list.
func (features Features) String() string {
if len(features) == 0 {
return "-"
}
list := make([]string, 0, len(features))
for _, feature := range features {
list = append(list, feature.String())
}
return strings.Join(list, ", ")
}
// FindByID finds and returns Feature by passed ID.
// If nothing found it returns empty Feature.
func (features Features) FindByID(id [16]byte) Feature {
for _, feature := range features {
if feature.ID == id {
return feature
}
}
return Feature{}
}
// FindByName finds and returns Feature by passed name.
// If nothing found it returns empty Feature.
func (features Features) FindByName(name string) Feature {
for _, feature := range features {
if feature.Name == name {
return feature
}
}
return Feature{}
}