basic app

This commit is contained in:
nquidox 2025-10-02 20:35:53 +03:00
parent 0a6e246a5c
commit 8d6c2b6687
30 changed files with 1469 additions and 0 deletions

57
config/config.go Normal file
View file

@ -0,0 +1,57 @@
package config
import (
log "github.com/sirupsen/logrus"
"os"
"strconv"
)
type Config struct {
Host string
ClientPort string
ServerPort string
LogLevel string
NumCPUs int
CheckPeriod int
TasksConfig TasksConfig
}
type TasksConfig struct {
RetryCount int
RetryMinutes int
}
func NewConfig() *Config {
return &Config{
Host: getEnv("APP_HOST", "0.0.0.0"),
ClientPort: getEnv("APP_PORT", "9050"),
ServerPort: getEnv("APP_SERVER_PORT", "9060"),
LogLevel: getEnv("APP_LOG_LEVEL", "debug"),
NumCPUs: getEnvInt("APP_NUMCPUS", -1),
CheckPeriod: getEnvInt("APP_CHECK_PERIOD", 6),
TasksConfig: TasksConfig{
RetryCount: getEnvInt("TASK_RETRY_COUNT", 3),
RetryMinutes: getEnvInt("TASK_RETRY_MINUTES", 5),
},
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func getEnvInt(key string, fallback int) int {
if value, ok := os.LookupEnv(key); ok {
num, err := strconv.Atoi(value)
if err != nil {
log.WithField("default", -1).Warn("Config | Can't parse value as int")
return fallback
}
return num
}
return fallback
}