自动检测本地数据库磁盘是否已满,如果已满,则不再写入访问日志

This commit is contained in:
刘祥超
2022-10-27 10:27:47 +08:00
parent 4b425e1698
commit 0a6111b2e5
6 changed files with 145 additions and 9 deletions

View File

@@ -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
}