72 lines
1.6 KiB
Go
72 lines
1.6 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, options LayerOptions) 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 {
|
||
|
From []string
|
||
|
Offset *int
|
||
|
Limit *int
|
||
|
|
||
|
Type *LayerType
|
||
|
Name *LayerName
|
||
|
Enabled *bool
|
||
|
}
|
||
|
|
||
|
func DefaultQueryLayerOptions() *QueryLayerOptions {
|
||
|
funcs := []QueryLayerOptionFunc{
|
||
|
WithLayerQueryOffset(0),
|
||
|
WithLayerQueryLimit(0),
|
||
|
}
|
||
|
|
||
|
opts := &QueryLayerOptions{}
|
||
|
for _, fn := range funcs {
|
||
|
fn(opts)
|
||
|
}
|
||
|
|
||
|
return opts
|
||
|
}
|
||
|
|
||
|
func WithLayerQueryOffset(offset int) QueryLayerOptionFunc {
|
||
|
return func(o *QueryLayerOptions) {
|
||
|
o.Offset = &offset
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithLayerQueryLimit(limit int) QueryLayerOptionFunc {
|
||
|
return func(o *QueryLayerOptions) {
|
||
|
o.Limit = &limit
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|