-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures.go
53 lines (49 loc) · 1.24 KB
/
features.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
package features
import (
"github.com/Clinet/clinet_cmds"
"github.com/Clinet/clinet_convos"
"github.com/Clinet/clinet_services"
)
type FeatureMap struct {
Features map[string]Feature `json:"features"`
}
var FM *FeatureMap
type Feature struct {
Toggle bool `json:"toggle,omitempty"`
Name string `json:"name"`
Desc string `json:"-"`
Init func() error `json:"-"`
Cmds []*cmds.Cmd `json:"-"`
ServiceChat services.Service `json:"-"`
ServiceConvo convos.ConvoService `json:"-"`
}
func SetFeatures(features map[string]Feature) {
if FM == nil {
FM = &FeatureMap{}
}
FM.Features = features
}
func IsEnabled(feature string) bool {
f, exists := FM.Features[feature]
if exists {
return f.Toggle
}
return false
}
func UpdateFeature(feature Feature) {
if FM != nil && FM.Features != nil {
if _, exists := FM.Features[feature.Name]; exists {
feature.Toggle = FM.Features[feature.Name].Toggle
FM.Features[feature.Name] = feature
}
}
}
func GetEnabledFeatures() []string {
enabledFeatures := make([]string, 0)
for fName, f := range FM.Features {
if f.Toggle {
enabledFeatures = append(enabledFeatures, fName)
}
}
return enabledFeatures
}