bouncer/internal/store/redis/layer_item.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

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