mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-19 04:10:28 +08:00
自动检测本地数据库磁盘是否已满,如果已满,则不再写入访问日志
This commit is contained in:
@@ -2,6 +2,7 @@ package dbutils
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -69,3 +70,26 @@ func SetGlobalVarMax(db *dbs.DB, variableName string, maxValue int) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsLocalAddr 是否为本地数据库
|
||||
func IsLocalAddr(addr string) bool {
|
||||
var host = addr
|
||||
if strings.Contains(addr, ":") {
|
||||
host, _, _ = net.SplitHostPort(addr)
|
||||
if len(host) == 0 {
|
||||
host = addr
|
||||
}
|
||||
}
|
||||
|
||||
if host == "127.0.0.1" || host == "::1" || host == "localhost" {
|
||||
return true
|
||||
}
|
||||
|
||||
interfaceAddrs, _ := net.InterfaceAddrs()
|
||||
for _, interfaceAddr := range interfaceAddrs {
|
||||
if strings.HasPrefix(interfaceAddr.String(), host+"/") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user