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

@@ -29,7 +29,7 @@ type PortCtx struct {
UpdateTime time.Time
}
type PortManager struct {
type Manager struct {
reservedPorts map[string]*PortCtx
usedPorts map[int]*PortCtx
freePorts map[int]struct{}
@@ -39,8 +39,8 @@ type PortManager struct {
mu sync.Mutex
}
func NewPortManager(netType string, bindAddr string, allowPorts map[int]struct{}) *PortManager {
pm := &PortManager{
func NewManager(netType string, bindAddr string, allowPorts map[int]struct{}) *Manager {
pm := &Manager{
reservedPorts: make(map[string]*PortCtx),
usedPorts: make(map[int]*PortCtx),
freePorts: make(map[int]struct{}),
@@ -48,7 +48,7 @@ func NewPortManager(netType string, bindAddr string, allowPorts map[int]struct{}
netType: netType,
}
if len(allowPorts) > 0 {
for port, _ := range allowPorts {
for port := range allowPorts {
pm.freePorts[port] = struct{}{}
}
} else {
@@ -60,7 +60,7 @@ func NewPortManager(netType string, bindAddr string, allowPorts map[int]struct{}
return pm
}
func (pm *PortManager) Acquire(name string, port int) (realPort int, err error) {
func (pm *Manager) Acquire(name string, port int) (realPort int, err error) {
portCtx := &PortCtx{
ProxyName: name,
Closed: false,
@@ -94,7 +94,7 @@ func (pm *PortManager) Acquire(name string, port int) (realPort int, err error)
// get random port
count := 0
maxTryTimes := 5
for k, _ := range pm.freePorts {
for k := range pm.freePorts {
count++
if count > maxTryTimes {
break
@@ -132,7 +132,7 @@ func (pm *PortManager) Acquire(name string, port int) (realPort int, err error)
return
}
func (pm *PortManager) isPortAvailable(port int) bool {
func (pm *Manager) isPortAvailable(port int) bool {
if pm.netType == "udp" {
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", pm.bindAddr, port))
if err != nil {
@@ -144,17 +144,17 @@ func (pm *PortManager) isPortAvailable(port int) bool {
}
l.Close()
return true
} else {
l, err := net.Listen(pm.netType, fmt.Sprintf("%s:%d", pm.bindAddr, port))
if err != nil {
return false
}
l.Close()
return true
}
l, err := net.Listen(pm.netType, fmt.Sprintf("%s:%d", pm.bindAddr, port))
if err != nil {
return false
}
l.Close()
return true
}
func (pm *PortManager) Release(port int) {
func (pm *Manager) Release(port int) {
pm.mu.Lock()
defer pm.mu.Unlock()
if ctx, ok := pm.usedPorts[port]; ok {
@@ -166,7 +166,7 @@ func (pm *PortManager) Release(port int) {
}
// Release reserved port if it isn't used in last 24 hours.
func (pm *PortManager) cleanReservedPortsWorker() {
func (pm *Manager) cleanReservedPortsWorker() {
for {
time.Sleep(CleanReservedPortsInterval)
pm.mu.Lock()