2023-04-24 20:52:12 +02:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type layerHeaderItem struct {
|
2024-06-27 17:03:50 +02:00
|
|
|
Proxy string `redis:"proxy"`
|
|
|
|
Name string `redis:"name"`
|
|
|
|
Revision int `redis:"revision"`
|
|
|
|
Type string `redis:"type"`
|
2023-04-24 20:52:12 +02:00
|
|
|
|
|
|
|
Weight int `redis:"weight"`
|
|
|
|
Enabled bool `redis:"enabled"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *layerHeaderItem) ToLayerHeader() (*store.LayerHeader, error) {
|
|
|
|
layerHeader := &store.LayerHeader{
|
2024-06-27 17:03:50 +02:00
|
|
|
Proxy: store.ProxyName(i.Proxy),
|
|
|
|
Name: store.LayerName(i.Name),
|
|
|
|
Revision: i.Revision,
|
|
|
|
Type: store.LayerType(i.Type),
|
|
|
|
Weight: i.Weight,
|
|
|
|
Enabled: i.Enabled,
|
2023-04-24 20:52:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return layerHeader, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type layerItem struct {
|
|
|
|
layerHeaderItem
|
|
|
|
Options *jsonWrapper[store.LayerOptions] `redis:"options"`
|
|
|
|
|
|
|
|
CreatedAt *jsonWrapper[time.Time] `redis:"created_at"`
|
|
|
|
UpdatedAt *jsonWrapper[time.Time] `redis:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *layerItem) ToLayer() (*store.Layer, error) {
|
|
|
|
layerHeader, err := i.layerHeaderItem.ToLayerHeader()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
layer := &store.Layer{
|
|
|
|
LayerHeader: *layerHeader,
|
|
|
|
}
|
|
|
|
|
|
|
|
if i.Options != nil {
|
|
|
|
layer.Options = i.Options.Value()
|
|
|
|
}
|
|
|
|
|
|
|
|
if i.CreatedAt != nil {
|
|
|
|
layer.CreatedAt = i.CreatedAt.Value()
|
|
|
|
}
|
|
|
|
|
|
|
|
if i.UpdatedAt != nil {
|
|
|
|
layer.UpdatedAt = i.UpdatedAt.Value()
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer, nil
|
|
|
|
}
|