File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package internal
22
33import (
44 "errors"
5+ "time"
56
67 "github.com/AlexxIT/SmartScaleConnect/pkg/core"
78 "github.com/AlexxIT/SmartScaleConnect/pkg/garmin"
@@ -21,9 +22,16 @@ const (
2122 AccZeppXiaomi = "zepp/xiaomi"
2223)
2324
24- var accounts = map [string ]core.Account {}
25+ var accounts map [string ]core.Account
26+ var cacheTS time.Time
2527
2628func 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+
2735 key := fields [0 ] + ":" + fields [1 ]
2836 if account , ok := accounts [key ]; ok {
2937 return account , nil
You can’t perform that action at this time.
0 commit comments