leonklingele ac4ce21d9c
🐛 Bug: Fix issues introduced in linting PR (#2319)
* internal: revert linting changes

Changes to the internal package should not have been made in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5.

* middleware/monitor: revert changes to exported field "ChartJSURL"

This is a breaking change introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5.

* middleware/monitor: fix error checking

Fix the errorenous error checking introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5.

* 🐛 Bug: Fix issues introduced in linting PR #2319

* 🐛 Bug: Fix issues introduced in linting PR #2319

* Bug: Fix issues introduced in linting PR #2319

---------

Co-authored-by: René Werner <rene@gofiber.io>
2023-02-02 15:57:40 +01:00

64 lines
1022 B
Go

package session
import (
"sync"
)
// go:generate msgp
// msgp -file="data.go" -o="data_msgp.go" -tests=false -unexported
type data struct {
sync.RWMutex
Data map[string]interface{}
}
var dataPool = sync.Pool{
New: func() interface{} {
d := new(data)
d.Data = make(map[string]interface{})
return d
},
}
func acquireData() *data {
return dataPool.Get().(*data) //nolint:forcetypeassert // We store nothing else in the pool
}
func (d *data) Reset() {
d.Lock()
d.Data = make(map[string]interface{})
d.Unlock()
}
func (d *data) Get(key string) interface{} {
d.RLock()
v := d.Data[key]
d.RUnlock()
return v
}
func (d *data) Set(key string, value interface{}) {
d.Lock()
d.Data[key] = value
d.Unlock()
}
func (d *data) Delete(key string) {
d.Lock()
delete(d.Data, key)
d.Unlock()
}
func (d *data) Keys() []string {
d.Lock()
keys := make([]string, 0, len(d.Data))
for k := range d.Data {
keys = append(keys, k)
}
d.Unlock()
return keys
}
func (d *data) Len() int {
return len(d.Data)
}