William Petit
3c1939f418
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
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"`
|
|
|
|
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,
|
|
}
|
|
|
|
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
|
|
}
|