bouncer/internal/store/layer_repository.go

79 lines
1.9 KiB
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package store
import (
"context"
)
type LayerOptions map[string]any
type LayerRepository interface {
CreateLayer(ctx context.Context, proxyName ProxyName, layerName LayerName, layerType LayerType, options LayerOptions) (*Layer, error)
UpdateLayer(ctx context.Context, proxyName ProxyName, layerName LayerName, funcs ...UpdateLayerOptionFunc) (*Layer, error)
DeleteLayer(ctx context.Context, proxyName ProxyName, layerName LayerName) error
GetLayer(ctx context.Context, proxyName ProxyName, layerName LayerName) (*Layer, error)
QueryLayers(ctx context.Context, proxyName ProxyName, funcs ...QueryLayerOptionFunc) ([]*LayerHeader, error)
}
type QueryLayerOptionFunc func(*QueryLayerOptions)
type QueryLayerOptions struct {
Type *LayerType
Name *LayerName
Enabled *bool
}
func DefaultQueryLayerOptions() *QueryLayerOptions {
funcs := []QueryLayerOptionFunc{}
opts := &QueryLayerOptions{}
for _, fn := range funcs {
fn(opts)
}
return opts
}
func WithLayerQueryType(layerType LayerType) QueryLayerOptionFunc {
return func(o *QueryLayerOptions) {
o.Type = &layerType
}
}
func WithLayerQueryName(layerName LayerName) QueryLayerOptionFunc {
return func(o *QueryLayerOptions) {
o.Name = &layerName
}
}
func WithLayerQueryEnabled(enabled bool) QueryLayerOptionFunc {
return func(o *QueryLayerOptions) {
o.Enabled = &enabled
}
}
type UpdateLayerOptionFunc func(*UpdateLayerOptions)
type UpdateLayerOptions struct {
Enabled *bool
Weight *int
Options *LayerOptions
}
func WithLayerUpdateEnabled(enabled bool) UpdateLayerOptionFunc {
return func(o *UpdateLayerOptions) {
o.Enabled = &enabled
}
}
func WithLayerUpdateWeight(weight int) UpdateLayerOptionFunc {
return func(o *UpdateLayerOptions) {
o.Weight = &weight
}
}
func WithLayerUpdateOptions(options LayerOptions) UpdateLayerOptionFunc {
return func(o *UpdateLayerOptions) {
o.Options = &options
}
}