mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 16:59:22 +02:00
registry: implement redis backend (#2179)
This commit is contained in:
parent
28155314e9
commit
a54d43b937
21 changed files with 772 additions and 64 deletions
48
internal/registry/redis/option.go
Normal file
48
internal/registry/redis/option.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultTTL = time.Second * 30
|
||||
|
||||
type config struct {
|
||||
tls *tls.Config
|
||||
ttl time.Duration
|
||||
getNow func() time.Time
|
||||
}
|
||||
|
||||
// An Option modifies the config..
|
||||
type Option func(*config)
|
||||
|
||||
// WithGetNow sets the time.Now function in the config.
|
||||
func WithGetNow(getNow func() time.Time) Option {
|
||||
return func(cfg *config) {
|
||||
cfg.getNow = getNow
|
||||
}
|
||||
}
|
||||
|
||||
// WithTLSConfig sets the tls.Config in the config.
|
||||
func WithTLSConfig(tlsConfig *tls.Config) Option {
|
||||
return func(cfg *config) {
|
||||
cfg.tls = tlsConfig
|
||||
}
|
||||
}
|
||||
|
||||
// WithTTL sets the ttl in the config.
|
||||
func WithTTL(ttl time.Duration) Option {
|
||||
return func(cfg *config) {
|
||||
cfg.ttl = ttl
|
||||
}
|
||||
}
|
||||
|
||||
func getConfig(options ...Option) *config {
|
||||
cfg := new(config)
|
||||
WithGetNow(time.Now)(cfg)
|
||||
WithTTL(defaultTTL)(cfg)
|
||||
for _, o := range options {
|
||||
o(cfg)
|
||||
}
|
||||
return cfg
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue