2020-05-15 09:39:16 +00:00
|
|
|
package leakybucket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha1"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Buckets is the struct used to hold buckets in the context of
|
|
|
|
// main.go the idea is to have one struct to rule them all
|
|
|
|
type Buckets struct {
|
2021-02-25 10:26:46 +00:00
|
|
|
wgDumpState *sync.WaitGroup
|
|
|
|
wgPour *sync.WaitGroup
|
|
|
|
Bucket_map *sync.Map
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBuckets create the Buckets struct
|
|
|
|
func NewBuckets() *Buckets {
|
|
|
|
return &Buckets{
|
2021-02-25 10:26:46 +00:00
|
|
|
wgDumpState: &sync.WaitGroup{},
|
|
|
|
wgPour: &sync.WaitGroup{},
|
|
|
|
Bucket_map: &sync.Map{},
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetKey(bucketCfg BucketFactory, stackkey string) string {
|
|
|
|
return fmt.Sprintf("%x", sha1.Sum([]byte(bucketCfg.Filter+stackkey+bucketCfg.Name)))
|
|
|
|
|
|
|
|
}
|