renamed ProxyEntry to RawEntry to avoid confusion with src/proxy/entry.go

This commit is contained in:
yusing 2024-09-22 04:13:42 +08:00
parent d39b68bfd8
commit 46281aa3b0
5 changed files with 24 additions and 22 deletions

View file

@ -164,8 +164,8 @@ func (cfg *Config) Statistics() map[string]any {
} }
} }
func (cfg *Config) DumpEntries() map[string]*M.ProxyEntry { func (cfg *Config) DumpEntries() map[string]*M.RawEntry {
entries := make(map[string]*M.ProxyEntry) entries := make(map[string]*M.RawEntry)
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) { cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) {
entries[alias] = r.Entry() entries[alias] = r.Entry()
}) })

View file

@ -10,7 +10,9 @@ import (
) )
type ( 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:"-"` Alias string `yaml:"-" json:"-"`
Scheme string `yaml:"scheme" json:"scheme"` Scheme string `yaml:"scheme" json:"scheme"`
Host string `yaml:"host" json:"host"` Host string `yaml:"host" json:"host"`
@ -24,12 +26,12 @@ type (
*D.ProxyProperties `yaml:"-" json:"proxy_properties"` *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 { if e.ProxyProperties == nil {
e.ProxyProperties = &D.ProxyProperties{} e.ProxyProperties = &D.ProxyProperties{}
} }

View file

@ -43,7 +43,7 @@ func (rp *ReverseProxyEntry) UseIdleWatcher() bool {
return rp.IdleTimeout > 0 && rp.DockerHost != "" return rp.IdleTimeout > 0 && rp.DockerHost != ""
} }
func ValidateEntry(m *M.ProxyEntry) (any, E.NestedError) { func ValidateEntry(m *M.RawEntry) (any, E.NestedError) {
m.SetDefaults() m.SetDefaults()
scheme, err := T.NewScheme(m.Scheme) scheme, err := T.NewScheme(m.Scheme)
if err.HasError() { if err.HasError() {
@ -63,7 +63,7 @@ func ValidateEntry(m *M.ProxyEntry) (any, E.NestedError) {
return entry, nil 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 var stopTimeOut time.Duration
host, err := T.ValidateHost(m.Host) 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) host, err := T.ValidateHost(m.Host)
b.Add(err) b.Add(err)

View file

@ -55,12 +55,12 @@ func (p *DockerProvider) LoadRoutesImpl() (routes R.Routes, err E.NestedError) {
// there may be some valid entries in `en` // there may be some valid entries in `en`
dups := entries.MergeFrom(newEntries) dups := entries.MergeFrom(newEntries)
// add the duplicate proxy entries to the error // 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) errors.Addf("duplicate alias %s", k)
}) })
} }
entries.RangeAll(func(_ string, e *M.ProxyEntry) { entries.RangeAll(func(_ string, e *M.RawEntry) {
e.DockerHost = p.dockerHost 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) entries, err := p.entriesFromContainerLabels(cont)
b.Add(err) b.Add(err)
entries.RangeAll(func(alias string, entry *M.ProxyEntry) { entries.RangeAll(func(alias string, entry *M.RawEntry) {
if routes.Has(alias) { if routes.Has(alias) {
b.Add(E.AlreadyExist("alias", alias)) b.Add(E.AlreadyExist("alias", alias))
} else { } 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. // Returns a list of proxy entries for a container.
// Always non-nil // 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() entries := M.NewProxyEntries()
// init entries map for all aliases // init entries map for all aliases
for _, a := range container.Aliases { for _, a := range container.Aliases {
entries.Store(a, &M.ProxyEntry{ entries.Store(a, &M.RawEntry{
Alias: a, Alias: a,
Host: p.hostname, Host: p.hostname,
ProxyProperties: container.ProxyProperties, ProxyProperties: container.ProxyProperties,
@ -156,7 +156,7 @@ func (p *DockerProvider) entriesFromContainerLabels(container D.Container) (M.Pr
return entries, errors.Build().Subject(container.ContainerName) 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) b := E.NewBuilder("errors in label %s", key)
defer b.To(&res) defer b.To(&res)
@ -169,7 +169,7 @@ func (p *DockerProvider) applyLabel(container D.Container, entries M.ProxyEntrie
} }
if lbl.Target == D.WildcardAlias { if lbl.Target == D.WildcardAlias {
// apply label for all aliases // 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() { if err = D.ApplyLabel(e, lbl); err.HasError() {
b.Add(err.Subject(lbl.Target)) b.Add(err.Subject(lbl.Target))
} }

View file

@ -13,7 +13,7 @@ import (
type ( type (
Route interface { Route interface {
RouteImpl RouteImpl
Entry() *M.ProxyEntry Entry() *M.RawEntry
Type() RouteType Type() RouteType
URL() *url.URL URL() *url.URL
} }
@ -28,7 +28,7 @@ type (
route struct { route struct {
RouteImpl RouteImpl
type_ RouteType type_ RouteType
entry *M.ProxyEntry entry *M.RawEntry
} }
) )
@ -40,7 +40,7 @@ const (
// function alias // function alias
var NewRoutes = F.NewMapOf[string, Route] 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) rt, err := P.ValidateEntry(en)
if err.HasError() { if err.HasError() {
return nil, err 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 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 return rt.entry
} }
@ -74,11 +74,11 @@ func (rt *route) URL() *url.URL {
return 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") b := E.NewBuilder("errors in routes")
routes := NewRoutes() routes := NewRoutes()
entries.RangeAll(func(alias string, entry *M.ProxyEntry) { entries.RangeAll(func(alias string, entry *M.RawEntry) {
entry.Alias = alias entry.Alias = alias
r, err := NewRoute(entry) r, err := NewRoute(entry)
if err.HasError() { if err.HasError() {