We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fac5b21 commit bb992b6Copy full SHA for bb992b6
1 file changed
internal/accounts.go
@@ -2,6 +2,7 @@ package internal
2
3
import (
4
"errors"
5
+ "time"
6
7
"github.com/AlexxIT/SmartScaleConnect/pkg/core"
8
"github.com/AlexxIT/SmartScaleConnect/pkg/garmin"
@@ -21,9 +22,16 @@ const (
21
22
AccZeppXiaomi = "zepp/xiaomi"
23
)
24
-var accounts = map[string]core.Account{}
25
+var accounts map[string]core.Account
26
+var cacheTS time.Time
27
28
func GetAccount(fields []string) (core.Account, error) {
29
+ // Clean accounts every 23 hours, because there is no logic for token expiration.
30
+ if now := time.Now(); now.After(cacheTS) {
31
+ accounts = map[string]core.Account{}
32
+ cacheTS = now.Add(23 * time.Hour)
33
+ }
34
+
35
key := fields[0] + ":" + fields[1]
36
if account, ok := accounts[key]; ok {
37
return account, nil
0 commit comments