github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/analytics.go (about) 1 package storage 2 3 import ( 4 "encoding/json" 5 6 "github.com/dgraph-io/badger/v2" 7 ) 8 9 const analyticsKey = "analytics" 10 11 func (s *Storage) SaveAnalytics(a interface{}) error { 12 v, err := json.Marshal(a) 13 if err != nil { 14 return err 15 } 16 return s.main.Update(func(txn *badger.Txn) error { 17 return txn.SetEntry(badger.NewEntry([]byte(analyticsKey), v)) 18 }) 19 } 20 21 func (s *Storage) LoadAnalytics(a interface{}) error { 22 err := s.main.View(func(txn *badger.Txn) error { 23 v, err := txn.Get([]byte(analyticsKey)) 24 if err != nil { 25 return err 26 } 27 return v.Value(func(val []byte) error { 28 return json.Unmarshal(val, a) 29 }) 30 }) 31 return err 32 }