fix by golint (#1822)

This commit is contained in:
fatedier
2020-05-24 17:48:37 +08:00
committed by GitHub
parent 2170c481ce
commit 8b75b8b837
80 changed files with 1315 additions and 1324 deletions

View File

@@ -28,9 +28,9 @@ import (
"github.com/fatedier/golib/errors"
)
type UdpProxy struct {
type UDPProxy struct {
*BaseProxy
cfg *config.UdpProxyConf
cfg *config.UDPProxyConf
realPort int
@@ -42,10 +42,10 @@ type UdpProxy struct {
workConn net.Conn
// sendCh is used for sending packages to workConn
sendCh chan *msg.UdpPacket
sendCh chan *msg.UDPPacket
// readCh is used for reading packages from workConn
readCh chan *msg.UdpPacket
readCh chan *msg.UDPPacket
// checkCloseCh is used for watching if workConn is closed
checkCloseCh chan int
@@ -53,15 +53,15 @@ type UdpProxy struct {
isClosed bool
}
func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
func (pxy *UDPProxy) Run() (remoteAddr string, err error) {
xl := pxy.xl
pxy.realPort, err = pxy.rc.UdpPortManager.Acquire(pxy.name, pxy.cfg.RemotePort)
pxy.realPort, err = pxy.rc.UDPPortManager.Acquire(pxy.name, pxy.cfg.RemotePort)
if err != nil {
return
}
defer func() {
if err != nil {
pxy.rc.UdpPortManager.Release(pxy.realPort)
pxy.rc.UDPPortManager.Release(pxy.realPort)
}
}()
@@ -81,8 +81,8 @@ func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
xl.Info("udp proxy listen port [%d]", pxy.cfg.RemotePort)
pxy.udpConn = udpConn
pxy.sendCh = make(chan *msg.UdpPacket, 1024)
pxy.readCh = make(chan *msg.UdpPacket, 1024)
pxy.sendCh = make(chan *msg.UDPPacket, 1024)
pxy.readCh = make(chan *msg.UDPPacket, 1024)
pxy.checkCloseCh = make(chan int)
// read message from workConn, if it returns any error, notify proxy to start a new workConn
@@ -110,7 +110,7 @@ func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
case *msg.Ping:
xl.Trace("udp work conn get ping message")
continue
case *msg.UdpPacket:
case *msg.UDPPacket:
if errRet := errors.PanicToError(func() {
xl.Trace("get udp message from workConn: %s", m.Content)
pxy.readCh <- m
@@ -142,15 +142,14 @@ func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
xl.Info("sender goroutine for udp work connection closed: %v", errRet)
conn.Close()
return
} else {
xl.Trace("send message to udp workConn: %s", udpMsg.Content)
metrics.Server.AddTrafficIn(
pxy.GetName(),
pxy.GetConf().GetBaseInfo().ProxyType,
int64(len(udpMsg.Content)),
)
continue
}
xl.Trace("send message to udp workConn: %s", udpMsg.Content)
metrics.Server.AddTrafficIn(
pxy.GetName(),
pxy.GetConf().GetBaseInfo().ProxyType,
int64(len(udpMsg.Content)),
)
continue
case <-ctx.Done():
xl.Info("sender goroutine for udp work connection closed")
return
@@ -196,17 +195,17 @@ func (pxy *UdpProxy) Run() (remoteAddr string, err error) {
// Response will be wrapped to be forwarded by work connection to server.
// Close readCh and sendCh at the end.
go func() {
udp.ForwardUserConn(udpConn, pxy.readCh, pxy.sendCh, int(pxy.serverCfg.UdpPacketSize))
udp.ForwardUserConn(udpConn, pxy.readCh, pxy.sendCh, int(pxy.serverCfg.UDPPacketSize))
pxy.Close()
}()
return remoteAddr, nil
}
func (pxy *UdpProxy) GetConf() config.ProxyConf {
func (pxy *UDPProxy) GetConf() config.ProxyConf {
return pxy.cfg
}
func (pxy *UdpProxy) Close() {
func (pxy *UDPProxy) Close() {
pxy.mu.Lock()
defer pxy.mu.Unlock()
if !pxy.isClosed {
@@ -223,5 +222,5 @@ func (pxy *UdpProxy) Close() {
close(pxy.readCh)
close(pxy.sendCh)
}
pxy.rc.UdpPortManager.Release(pxy.realPort)
pxy.rc.UDPPortManager.Release(pxy.realPort)
}