diff --git a/src/config/config.go b/src/config/config.go index ca0cceb..3b05e29 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -164,8 +164,8 @@ func (cfg *Config) Statistics() map[string]any { } } -func (cfg *Config) DumpEntries() map[string]*M.ProxyEntry { - entries := make(map[string]*M.ProxyEntry) +func (cfg *Config) DumpEntries() map[string]*M.RawEntry { + entries := make(map[string]*M.RawEntry) cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) { entries[alias] = r.Entry() }) diff --git a/src/models/proxy_entry.go b/src/models/raw_entry.go similarity index 89% rename from src/models/proxy_entry.go rename to src/models/raw_entry.go index 8d5e5f5..25c8a15 100644 --- a/src/models/proxy_entry.go +++ b/src/models/raw_entry.go @@ -10,7 +10,9 @@ import ( ) type ( - ProxyEntry struct { // raw entry object before validation + RawEntry struct { + // raw entry object before validation + // loaded from docker labels or yaml file Alias string `yaml:"-" json:"-"` Scheme string `yaml:"scheme" json:"scheme"` Host string `yaml:"host" json:"host"` @@ -24,12 +26,12 @@ type ( *D.ProxyProperties `yaml:"-" json:"proxy_properties"` } - ProxyEntries = F.Map[string, *ProxyEntry] + RawEntries = F.Map[string, *RawEntry] ) -var NewProxyEntries = F.NewMapOf[string, *ProxyEntry] +var NewProxyEntries = F.NewMapOf[string, *RawEntry] -func (e *ProxyEntry) SetDefaults() { +func (e *RawEntry) SetDefaults() { if e.ProxyProperties == nil { e.ProxyProperties = &D.ProxyProperties{} } diff --git a/src/proxy/entry.go b/src/proxy/entry.go index e1ce85f..e4e6b23 100644 --- a/src/proxy/entry.go +++ b/src/proxy/entry.go @@ -43,7 +43,7 @@ func (rp *ReverseProxyEntry) UseIdleWatcher() bool { return rp.IdleTimeout > 0 && rp.DockerHost != "" } -func ValidateEntry(m *M.ProxyEntry) (any, E.NestedError) { +func ValidateEntry(m *M.RawEntry) (any, E.NestedError) { m.SetDefaults() scheme, err := T.NewScheme(m.Scheme) if err.HasError() { @@ -63,7 +63,7 @@ func ValidateEntry(m *M.ProxyEntry) (any, E.NestedError) { return entry, nil } -func validateRPEntry(m *M.ProxyEntry, s T.Scheme, b E.Builder) *ReverseProxyEntry { +func validateRPEntry(m *M.RawEntry, s T.Scheme, b E.Builder) *ReverseProxyEntry { var stopTimeOut time.Duration host, err := T.ValidateHost(m.Host) @@ -121,7 +121,7 @@ func validateRPEntry(m *M.ProxyEntry, s T.Scheme, b E.Builder) *ReverseProxyEntr } } -func validateStreamEntry(m *M.ProxyEntry, b E.Builder) *StreamEntry { +func validateStreamEntry(m *M.RawEntry, b E.Builder) *StreamEntry { host, err := T.ValidateHost(m.Host) b.Add(err) diff --git a/src/proxy/provider/docker_provider.go b/src/proxy/provider/docker_provider.go index 47beb95..dbfb2ec 100755 --- a/src/proxy/provider/docker_provider.go +++ b/src/proxy/provider/docker_provider.go @@ -55,12 +55,12 @@ func (p *DockerProvider) LoadRoutesImpl() (routes R.Routes, err E.NestedError) { // there may be some valid entries in `en` dups := entries.MergeFrom(newEntries) // add the duplicate proxy entries to the error - dups.RangeAll(func(k string, v *M.ProxyEntry) { + dups.RangeAll(func(k string, v *M.RawEntry) { errors.Addf("duplicate alias %s", k) }) } - entries.RangeAll(func(_ string, e *M.ProxyEntry) { + entries.RangeAll(func(_ string, e *M.RawEntry) { e.DockerHost = p.dockerHost }) @@ -96,7 +96,7 @@ func (p *DockerProvider) OnEvent(event W.Event, routes R.Routes) (res EventResul entries, err := p.entriesFromContainerLabels(cont) b.Add(err) - entries.RangeAll(func(alias string, entry *M.ProxyEntry) { + entries.RangeAll(func(alias string, entry *M.RawEntry) { if routes.Has(alias) { b.Add(E.AlreadyExist("alias", alias)) } else { @@ -115,12 +115,12 @@ func (p *DockerProvider) OnEvent(event W.Event, routes R.Routes) (res EventResul // Returns a list of proxy entries for a container. // Always non-nil -func (p *DockerProvider) entriesFromContainerLabels(container D.Container) (M.ProxyEntries, E.NestedError) { +func (p *DockerProvider) entriesFromContainerLabels(container D.Container) (M.RawEntries, E.NestedError) { entries := M.NewProxyEntries() // init entries map for all aliases for _, a := range container.Aliases { - entries.Store(a, &M.ProxyEntry{ + entries.Store(a, &M.RawEntry{ Alias: a, Host: p.hostname, ProxyProperties: container.ProxyProperties, @@ -156,7 +156,7 @@ func (p *DockerProvider) entriesFromContainerLabels(container D.Container) (M.Pr return entries, errors.Build().Subject(container.ContainerName) } -func (p *DockerProvider) applyLabel(container D.Container, entries M.ProxyEntries, key, val string) (res E.NestedError) { +func (p *DockerProvider) applyLabel(container D.Container, entries M.RawEntries, key, val string) (res E.NestedError) { b := E.NewBuilder("errors in label %s", key) defer b.To(&res) @@ -169,7 +169,7 @@ func (p *DockerProvider) applyLabel(container D.Container, entries M.ProxyEntrie } if lbl.Target == D.WildcardAlias { // apply label for all aliases - entries.RangeAll(func(a string, e *M.ProxyEntry) { + entries.RangeAll(func(a string, e *M.RawEntry) { if err = D.ApplyLabel(e, lbl); err.HasError() { b.Add(err.Subject(lbl.Target)) } diff --git a/src/route/route.go b/src/route/route.go index e3c9209..ae1f92a 100755 --- a/src/route/route.go +++ b/src/route/route.go @@ -13,7 +13,7 @@ import ( type ( Route interface { RouteImpl - Entry() *M.ProxyEntry + Entry() *M.RawEntry Type() RouteType URL() *url.URL } @@ -28,7 +28,7 @@ type ( route struct { RouteImpl type_ RouteType - entry *M.ProxyEntry + entry *M.RawEntry } ) @@ -40,7 +40,7 @@ const ( // function alias var NewRoutes = F.NewMapOf[string, Route] -func NewRoute(en *M.ProxyEntry) (Route, E.NestedError) { +func NewRoute(en *M.RawEntry) (Route, E.NestedError) { rt, err := P.ValidateEntry(en) if err.HasError() { return nil, err @@ -61,7 +61,7 @@ func NewRoute(en *M.ProxyEntry) (Route, E.NestedError) { return &route{RouteImpl: rt.(RouteImpl), entry: en, type_: t}, err } -func (rt *route) Entry() *M.ProxyEntry { +func (rt *route) Entry() *M.RawEntry { return rt.entry } @@ -74,11 +74,11 @@ func (rt *route) URL() *url.URL { return url } -func FromEntries(entries M.ProxyEntries) (Routes, E.NestedError) { +func FromEntries(entries M.RawEntries) (Routes, E.NestedError) { b := E.NewBuilder("errors in routes") routes := NewRoutes() - entries.RangeAll(func(alias string, entry *M.ProxyEntry) { + entries.RangeAll(func(alias string, entry *M.RawEntry) { entry.Alias = alias r, err := NewRoute(entry) if err.HasError() {