Style: cleanup code

This commit is contained in:
Dreamacro
2021-03-24 01:00:21 +08:00
parent 807d53c1e7
commit d759d16944
9 changed files with 40 additions and 50 deletions

View File

@ -16,19 +16,19 @@ import (
"github.com/Dreamacro/clash/tunnel"
)
type HttpListener struct {
type HTTPListener struct {
net.Listener
address string
closed bool
cache *cache.Cache
}
func NewHttpProxy(addr string) (*HttpListener, error) {
func NewHTTPProxy(addr string) (*HTTPListener, error) {
l, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
}
hl := &HttpListener{l, addr, false, cache.New(30 * time.Second)}
hl := &HTTPListener{l, addr, false, cache.New(30 * time.Second)}
go func() {
log.Infoln("HTTP proxy listening at: %s", addr)
@ -48,12 +48,12 @@ func NewHttpProxy(addr string) (*HttpListener, error) {
return hl, nil
}
func (l *HttpListener) Close() {
func (l *HTTPListener) Close() {
l.closed = true
l.Listener.Close()
}
func (l *HttpListener) Address() string {
func (l *HTTPListener) Address() string {
return l.address
}

View File

@ -19,7 +19,7 @@ var (
socksListener *socks.SockListener
socksUDPListener *socks.SockUDPListener
httpListener *http.HttpListener
httpListener *http.HTTPListener
redirListener *redir.RedirListener
redirUDPListener *redir.RedirUDPListener
tproxyListener *redir.TProxyListener
@ -78,7 +78,7 @@ func ReCreateHTTP(port int) error {
}
var err error
httpListener, err = http.NewHttpProxy(addr)
httpListener, err = http.NewHTTPProxy(addr)
if err != nil {
return err
}
@ -316,9 +316,8 @@ func genAddr(host string, port int, allowLan bool) string {
if allowLan {
if host == "*" {
return fmt.Sprintf(":%d", port)
} else {
return fmt.Sprintf("%s:%d", host, port)
}
return fmt.Sprintf("%s:%d", host, port)
}
return fmt.Sprintf("127.0.0.1:%d", port)