bouncer/internal/store/redis/proxy_item.go
William Petit 3c1939f418
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
feat: add revision number to proxy and layers to identify changes
2024-06-27 17:03:50 +02:00

63 lines
1.2 KiB
Go

package redis
import (
"time"
"forge.cadoles.com/cadoles/bouncer/internal/store"
"github.com/pkg/errors"
)
type proxyHeaderItem struct {
Name string `redis:"name"`
Revision int `redis:"revision"`
Weight int `redis:"weight"`
Enabled bool `redis:"enabled"`
CreatedAt *jsonWrapper[time.Time] `redis:"created_at"`
UpdatedAt *jsonWrapper[time.Time] `redis:"updated_at"`
}
func (i *proxyHeaderItem) ToProxyHeader() (*store.ProxyHeader, error) {
proxyHeader := &store.ProxyHeader{
Name: store.ProxyName(i.Name),
Revision: i.Revision,
Weight: i.Weight,
Enabled: i.Enabled,
}
return proxyHeader, nil
}
type proxyItem struct {
proxyHeaderItem
To string `redis:"to"`
From *jsonWrapper[[]string] `redis:"from"`
}
func (i *proxyItem) ToProxy() (*store.Proxy, error) {
proxyHeader, err := i.proxyHeaderItem.ToProxyHeader()
if err != nil {
return nil, errors.WithStack(err)
}
proxy := &store.Proxy{
ProxyHeader: *proxyHeader,
To: i.To,
}
if i.CreatedAt != nil {
proxy.CreatedAt = i.CreatedAt.Value()
}
if i.UpdatedAt != nil {
proxy.UpdatedAt = i.UpdatedAt.Value()
}
if i.From != nil {
proxy.From = i.From.Value()
}
return proxy, nil
}