aboutsummaryrefslogtreecommitdiff
path: root/persistence
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-05 22:56:12 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-05 22:56:12 +0300
commitec1197f83cfa064ea8170d4b9f8a9ec021f88a87 (patch)
treee0e5bb347bf70ea625659f68f6d7ce1726a504d0 /persistence
parent753a488c9de0a188dbc963b7ba967b9deb87bae2 (diff)
Add /config command
Diffstat (limited to 'persistence')
-rw-r--r--persistence/sessions.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/persistence/sessions.go b/persistence/sessions.go
index d15c4f3..85c84be 100644
--- a/persistence/sessions.go
+++ b/persistence/sessions.go
@@ -23,7 +23,8 @@ type SessionsMap struct {
// Session is a key-values subtree
type Session struct {
- Login string `yaml:":login"`
+ Login string `yaml:":login"`
+ Timezone string `yaml:":timezone"`
}
var sessionDB *SessionsYamlDB
@@ -75,3 +76,35 @@ func initYamlDB(path string, dataPtr *SessionsMap) (*SessionsYamlDB, error) {
Data: dataPtr,
}, nil
}
+
+// Get retrieves a session value
+func (s *Session) Get(key string) (string, error) {
+ switch key {
+ case "timezone":
+ return s.Timezone, nil
+ }
+
+ return "", errors.New("Unknown session property")
+}
+
+// ToMap converts the session to a map
+func (s *Session) ToMap() map[string]string {
+ m := make(map[string]string)
+ for _, configKey := range []string{"timezone"} {
+ value, _ := s.Get(configKey)
+ m[configKey] = value
+ }
+
+ return m
+}
+
+// Set sets a session value
+func (s *Session) Set(key string, value string) (string, error) {
+ switch key {
+ case "timezone":
+ s.Timezone = value
+ return value, nil
+ }
+
+ return "", errors.New("Unknown session property")
+}