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"` 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), Type: store.LayerType(i.Type), Weight: i.Weight, Enabled: i.Enabled, } return layerHeader, nil } type layerItem struct { layerHeaderItem Options *jsonWrapper[map[string]any] `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 }