forked from cert-lv/graphoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.go
56 lines (46 loc) · 1.16 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
54
55
56
package main
import (
"fmt"
yaml "gopkg.in/yaml.v3"
)
var (
// A list of new features for the current service's version.
// Will be displayed once for each user
features = []string{}
)
/*
* Load new features from a YAML file
*/
func loadFeatures() error {
buffer, err := loadFileIntoString(config.Features)
if err != nil {
return fmt.Errorf("Failed to read new features file '%s': %s", config.Features, err.Error())
}
err = yaml.Unmarshal([]byte(buffer), &features)
if err != nil {
return fmt.Errorf("Failed unmarshalling new features yaml: %s", err.Error())
}
if len(features) > 0 {
log.Debug().Msgf("New features loaded: %v", features)
}
return nil
}
/*
* Prevent future notifications after the first one
*/
func (a *Account) hideFeatures() {
if a.SeenFeatures == features[0] {
log.Debug().
Str("username", a.Username).
Msg("No new features notifications to disable")
return
}
err := a.update("seenFeatures", features[0])
if err != nil {
log.Error().Msg("Can't update account to hide new features notifications: " + err.Error())
return
}
log.Debug().
Str("username", a.Username).
Msg("New features notifications are hidden")
}