From cdcc1240eca0e72c95a19b05be99191f6766acf0 Mon Sep 17 00:00:00 2001 From: fatedier Date: Tue, 27 Dec 2016 02:52:32 +0800 Subject: [PATCH] vhost: fix a wrong usage of sort.Reverse --- src/models/server/server.go | 6 ++++++ src/utils/vhost/router.go | 14 +++++++------- src/utils/vhost/vhost.go | 4 +++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/models/server/server.go b/src/models/server/server.go index e2f3e2c..419f6b8 100644 --- a/src/models/server/server.go +++ b/src/models/server/server.go @@ -148,6 +148,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, domain, "") p.listeners = append(p.listeners, l) } else { for _, location := range p.Locations { @@ -155,6 +156,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, domain, location) p.listeners = append(p.listeners, l) } } @@ -165,6 +167,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, p.SubDomain, "") p.listeners = append(p.listeners, l) } else { for _, location := range p.Locations { @@ -172,6 +175,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type http listen for host [%s] location [%s]", p.Name, p.SubDomain, location) p.listeners = append(p.listeners, l) } } @@ -182,6 +186,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type https listen for host [%s]", p.Name, domain) p.listeners = append(p.listeners, l) } if p.SubDomain != "" { @@ -189,6 +194,7 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { if err != nil { return err } + log.Info("ProxyName [%s], type https listen for host [%s]", p.Name, p.SubDomain) p.listeners = append(p.listeners, l) } } diff --git a/src/utils/vhost/router.go b/src/utils/vhost/router.go index df0f832..975119e 100644 --- a/src/utils/vhost/router.go +++ b/src/utils/vhost/router.go @@ -29,7 +29,7 @@ func (r *VhostRouters) Add(domain, location string, l *Listener) { vrs, found := r.RouterByDomain[domain] if !found { - vrs = make([]*VhostRouter, 0) + vrs = make([]*VhostRouter, 0, 1) } vr := &VhostRouter{ @@ -39,25 +39,25 @@ func (r *VhostRouters) Add(domain, location string, l *Listener) { } vrs = append(vrs, vr) - sort.Reverse(ByLocation(vrs)) + sort.Sort(sort.Reverse(ByLocation(vrs))) r.RouterByDomain[domain] = vrs } -func (r *VhostRouters) Del(l *Listener) { +func (r *VhostRouters) Del(domain, location string) { r.mutex.Lock() defer r.mutex.Unlock() - vrs, found := r.RouterByDomain[l.name] + vrs, found := r.RouterByDomain[domain] if !found { return } for i, vr := range vrs { - if vr.listener == l { + if vr.location == location { if len(vrs) > i+1 { - r.RouterByDomain[l.name] = append(vrs[:i], vrs[i+1:]...) + r.RouterByDomain[domain] = append(vrs[:i], vrs[i+1:]...) } else { - r.RouterByDomain[l.name] = vrs[:i] + r.RouterByDomain[domain] = vrs[:i] } } } diff --git a/src/utils/vhost/vhost.go b/src/utils/vhost/vhost.go index 25b128a..08ce254 100644 --- a/src/utils/vhost/vhost.go +++ b/src/utils/vhost/vhost.go @@ -63,6 +63,7 @@ func (v *VhostMuxer) Listen(name, location, rewriteHost, userName, passWord stri l = &Listener{ name: name, + location: location, rewriteHost: rewriteHost, userName: userName, passWord: passWord, @@ -153,6 +154,7 @@ func (v *VhostMuxer) handle(c *conn.Conn) { type Listener struct { name string + location string rewriteHost string userName string passWord string @@ -180,7 +182,7 @@ func (l *Listener) Accept() (*conn.Conn, error) { } func (l *Listener) Close() error { - l.mux.registryRouter.Del(l) + l.mux.registryRouter.Del(l.name, l.location) close(l.accept) return nil }