mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-02 20:06:03 +02:00
* session: add accessed at date
* authorize: track session and service account access times
* Revert "databroker: add support for field masks on Put (#3210)"
This reverts commit 2dc778035d
.
* add test
* fix data race in test
* add deadline for update
* track dropped accesses
36 lines
864 B
Go
36 lines
864 B
Go
package sets
|
|
|
|
// A SizeLimitedStringSet is a StringSet which is limited to a given size. Once
|
|
// the capacity is reached an element will be removed at random.
|
|
type SizeLimitedStringSet struct {
|
|
m map[string]struct{}
|
|
capacity int
|
|
}
|
|
|
|
// NewSizeLimitedStringSet create a new SizeLimitedStringSet.
|
|
func NewSizeLimitedStringSet(capacity int) *SizeLimitedStringSet {
|
|
return &SizeLimitedStringSet{
|
|
m: make(map[string]struct{}),
|
|
capacity: capacity,
|
|
}
|
|
}
|
|
|
|
// Add adds an element to the set.
|
|
func (s *SizeLimitedStringSet) Add(element string) {
|
|
s.m[element] = struct{}{}
|
|
for len(s.m) > s.capacity {
|
|
for k := range s.m {
|
|
delete(s.m, k)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
// ForEach iterates over all the elements in the set.
|
|
func (s *SizeLimitedStringSet) ForEach(callback func(element string) bool) {
|
|
for k := range s.m {
|
|
if !callback(k) {
|
|
return
|
|
}
|
|
}
|
|
}
|