2024-05-03 17:11:56 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type App struct {
|
2024-05-04 15:36:57 +00:00
|
|
|
// configuration for server
|
2024-05-03 17:11:56 +00:00
|
|
|
Debug bool
|
|
|
|
Prefork bool
|
|
|
|
Host string
|
|
|
|
Port int
|
|
|
|
ProxyHeader string
|
|
|
|
AllowOrigin string
|
|
|
|
SecretKey string
|
|
|
|
LogLevel string
|
2024-05-04 15:36:57 +00:00
|
|
|
// configuration for prober (client)
|
|
|
|
ServerEndpoint string
|
|
|
|
ApiKey string
|
|
|
|
AcceptTor bool
|
|
|
|
TorSocks string
|
2024-05-03 17:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var app = &App{}
|
|
|
|
|
|
|
|
func AppCfg() *App {
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// loads App configuration
|
2024-05-03 17:11:56 +00:00
|
|
|
func LoadApp() {
|
2024-05-04 15:36:57 +00:00
|
|
|
// server configuration
|
2024-05-03 17:11:56 +00:00
|
|
|
app.Host = os.Getenv("APP_HOST")
|
|
|
|
app.Port, _ = strconv.Atoi(os.Getenv("APP_PORT"))
|
|
|
|
app.Debug, _ = strconv.ParseBool(os.Getenv("APP_DEBUG"))
|
|
|
|
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")
|
|
|
|
app.LogLevel = os.Getenv("LOG_LEVEL")
|
|
|
|
if app.LogLevel == "" {
|
|
|
|
app.LogLevel = "INFO"
|
|
|
|
}
|
|
|
|
if app.Debug {
|
|
|
|
app.LogLevel = "DEBUG"
|
|
|
|
}
|
2024-05-04 15:36:57 +00:00
|
|
|
// 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")
|
2024-05-03 17:11:56 +00:00
|
|
|
}
|