mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-11-17 01:17:37 +00:00
46bc3dc2e8
The log level for the apps is using `log/slog` from Go standard library. This commit change log format for fiber http logger to match with the slog standard log format (date and time). This commit also remove `APP_DEBUG` field from config struct. TODO: Use `slog` for default app output. Note that in this commit, the `slog` output only implemented in `cron` "db migrate" and probe client.
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type App struct {
|
|
// general config
|
|
LogLevel string
|
|
// configuration for server
|
|
Prefork bool
|
|
Host string
|
|
Port int
|
|
ProxyHeader string
|
|
AllowOrigin string
|
|
SecretKey string
|
|
// configuration for prober (client)
|
|
ServerEndpoint string
|
|
ApiKey string
|
|
AcceptTor bool
|
|
TorSocks string
|
|
}
|
|
|
|
var app = &App{}
|
|
|
|
func AppCfg() *App {
|
|
return app
|
|
}
|
|
|
|
// loads App configuration
|
|
func LoadApp() {
|
|
// general config
|
|
app.LogLevel = os.Getenv("LOG_LEVEL")
|
|
switch app.LogLevel {
|
|
case "DEBUG":
|
|
slog.SetLogLoggerLevel(slog.LevelDebug)
|
|
case "ERROR":
|
|
slog.SetLogLoggerLevel(slog.LevelError)
|
|
case "WARN":
|
|
slog.SetLogLoggerLevel(slog.LevelWarn)
|
|
default:
|
|
slog.SetLogLoggerLevel(slog.LevelInfo)
|
|
}
|
|
|
|
// server configuration
|
|
app.Host = os.Getenv("APP_HOST")
|
|
app.Port, _ = strconv.Atoi(os.Getenv("APP_PORT"))
|
|
app.Prefork, _ = strconv.ParseBool(os.Getenv("APP_PREFORK"))
|
|
app.ProxyHeader = os.Getenv("APP_PROXY_HEADER")
|
|
app.AllowOrigin = os.Getenv("APP_ALLOW_ORIGIN")
|
|
app.SecretKey = os.Getenv("SECRET_KEY")
|
|
|
|
// prober configuration
|
|
app.ServerEndpoint = os.Getenv("SERVER_ENDPOINT")
|
|
app.ApiKey = os.Getenv("API_KEY")
|
|
app.AcceptTor, _ = strconv.ParseBool(os.Getenv("ACCEPT_TOR"))
|
|
app.TorSocks = os.Getenv("TOR_SOCKS")
|
|
}
|