fix: set connection limits for database

This commit is contained in:
JustSong
2023-08-12 10:05:25 +08:00
parent 2b088a1678
commit 466005de07
3 changed files with 28 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import (
"log"
"math/rand"
"net"
"os"
"os/exec"
"runtime"
"strconv"
@@ -177,3 +178,15 @@ func Max(a int, b int) int {
return b
}
}
func GetOrDefault(env string, defaultValue int) int {
if env == "" || os.Getenv(env) == "" {
return defaultValue
}
num, err := strconv.Atoi(os.Getenv(env))
if err != nil {
SysError(fmt.Sprintf("failed to parse %s: %s, using default value: %d", env, err.Error(), defaultValue))
return defaultValue
}
return num
}