mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 10:56:28 +02:00
* pkg: add storage package Which contains storage.Backend interface to initial support for multiple backend storage. * pkg/storage: add inmemory storage * internal/databroker: use storage.Backend interface Instead of implementing multiple databroker server implementation for each kind of storage backend, we use only one databroker server implementation, which is supported multiple storage backends, which satisfy storage.Backend interface.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package databroker
|
|
|
|
import "time"
|
|
|
|
var (
|
|
// DefaultDeletePermanentlyAfter is the default amount of time to wait before deleting
|
|
// a record permanently.
|
|
DefaultDeletePermanentlyAfter = time.Hour
|
|
// DefaultBTreeDegree is the default number of items to store in each node of the BTree.
|
|
DefaultBTreeDegree = 8
|
|
)
|
|
|
|
type serverConfig struct {
|
|
deletePermanentlyAfter time.Duration
|
|
btreeDegree int
|
|
}
|
|
|
|
func newServerConfig(options ...ServerOption) *serverConfig {
|
|
cfg := new(serverConfig)
|
|
WithDeletePermanentlyAfter(DefaultDeletePermanentlyAfter)(cfg)
|
|
WithBTreeDegree(DefaultBTreeDegree)(cfg)
|
|
for _, option := range options {
|
|
option(cfg)
|
|
}
|
|
return cfg
|
|
}
|
|
|
|
// A ServerOption customizes the server.
|
|
type ServerOption func(*serverConfig)
|
|
|
|
// WithBTreeDegree sets the number of items to store in each node of the BTree.
|
|
func WithBTreeDegree(degree int) ServerOption {
|
|
return func(cfg *serverConfig) {
|
|
cfg.btreeDegree = degree
|
|
}
|
|
}
|
|
|
|
// WithDeletePermanentlyAfter sets the deletePermanentlyAfter duration.
|
|
// If a record is deleted via Delete, it will be permanently deleted after
|
|
// the given duration.
|
|
func WithDeletePermanentlyAfter(dur time.Duration) ServerOption {
|
|
return func(cfg *serverConfig) {
|
|
cfg.deletePermanentlyAfter = dur
|
|
}
|
|
}
|