Tesla Command: implement token storage (#12021)

This commit is contained in:
andig 2024-02-03 13:04:52 +01:00 • committed by GitHub
parent 7e37fb4a8f
commit 5627f57ebb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 203 additions and 46 deletions

View file

@ -1,6 +1,7 @@
package settings
import (
"cmp"
"encoding/json"
"errors"
"slices"
@ -43,6 +44,18 @@ func Persist() error {
return db.Instance.Save(settings).Error
}
func All() []setting {
mu.RLock()
defer mu.RUnlock()
res := slices.Clone(settings)
slices.SortFunc(res, func(i, j setting) int {
return cmp.Compare(i.Key, j.Key)
})
return res
}
func SetString(key string, val string) {
mu.Lock()
defer mu.Unlock()