bouncer/internal/store/layer_repository.go
William Petit e66938f1d3
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
feat: initial commit
2023-05-21 22:27:25 +02:00

79 lines
1.9 KiB
Go

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
}
}