1
0
mirror of https://github.com/alm494/sql_proxy.git synced 2026-04-22 19:33:55 +02:00
This commit is contained in:
Almaz Sharipov
2025-03-31 07:17:38 +03:00
parent eb395326a1
commit 593fb504b6
2 changed files with 20 additions and 21 deletions
+14 -14
View File
@@ -5,19 +5,19 @@ import (
"strconv"
)
func GetIntEnvOrDefault(env string, defaultValue uint32) uint32 {
strValue := os.Getenv(env)
if len(strValue) == 0 {
return defaultValue
} else {
uintValue, err := strconv.ParseUint(strValue, 10, 32)
if err != nil {
Log.Error(env + " env value cannot be parsed as uint, reset to " + strconv.FormatUint(uint64(defaultValue), 10))
return defaultValue
} else {
return uint32(uintValue)
}
func GetEnvString(key, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultValue
}
func GetEnvInt(key string, defaultValue int) int {
if value, exists := os.LookupEnv(key); exists {
if intValue, err := strconv.Atoi(value); err == nil {
return intValue
}
Log.Errorf("Invalid integer value for %s, using default value: %d", key, defaultValue)
}
return defaultValue
}
+6 -7
View File
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"net/http"
"os"
"sql-proxy/src/app"
"sql-proxy/src/db"
@@ -18,12 +17,12 @@ func main() {
var err error
// Application params taken from OS environment
app.Log.SetLevel(logrus.Level(app.GetIntEnvOrDefault("LOG_LEVEL", 2)))
bindAddress := os.Getenv("BIND_ADDR")
bindPort := app.GetIntEnvOrDefault("BIND_PORT", 8080)
db.MaxRows = app.GetIntEnvOrDefault("MAX_ROWS", 10000)
tlsCert := os.Getenv("TLS_CERT")
tlsKey := os.Getenv("TLS_KEY")
app.Log.SetLevel(logrus.Level(app.GetEnvInt("LOG_LEVEL", 2)))
bindAddress := app.GetEnvString("BIND_ADDR", "localhost")
bindPort := app.GetEnvInt("BIND_PORT", 8080)
db.MaxRows = uint32(app.GetEnvInt("MAX_ROWS", 10000))
tlsCert := app.GetEnvString("TLS_CERT", "")
tlsKey := app.GetEnvString("TLS_KEY", "")
// Scheduled maintenance task
go db.Handler.RunMaintenance()