mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-25 06:26:34 +08:00
优化代码
This commit is contained in:
@@ -34,10 +34,7 @@ func IsLocalIP(ipString string) bool {
|
||||
|
||||
// IPv6
|
||||
if strings.Contains(ipString, ":") {
|
||||
if ip.String() == "::1" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return ip.String() == "::1"
|
||||
}
|
||||
|
||||
// IPv4
|
||||
|
||||
@@ -72,7 +72,7 @@ func (this *IntMap[K, V]) Has(k K) bool {
|
||||
func (this *IntMap[K, V]) Get(k K) (value V) {
|
||||
var index = this.index(k)
|
||||
this.lockers[index].RLock()
|
||||
value, _ = this.m[index][k]
|
||||
value = this.m[index][k]
|
||||
this.lockers[index].RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ func setMaxMemory(memoryGB int) {
|
||||
if memoryGB <= 0 {
|
||||
memoryGB = 1
|
||||
}
|
||||
var maxMemoryBytes int64 = 0
|
||||
var maxMemoryBytes int64
|
||||
if memoryGB > 10 {
|
||||
maxMemoryBytes = int64(memoryGB-2) << 30 // 超过10G内存的允许剩余2G内存
|
||||
} else {
|
||||
|
||||
@@ -85,7 +85,7 @@ func (this *RateLimitWriter) write(p []byte) (n int, err error) {
|
||||
this.written += n
|
||||
|
||||
if this.written >= this.rateBytes {
|
||||
var duration = 1*time.Second - time.Now().Sub(this.before)
|
||||
var duration = 1*time.Second - time.Since(this.before)
|
||||
if duration > 0 {
|
||||
time.Sleep(duration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user