Version Inicial

This commit is contained in:
2026-04-13 21:42:04 +02:00
commit f5dc96eee5
24 changed files with 2630 additions and 0 deletions

65
internal/config/config.go Normal file
View File

@@ -0,0 +1,65 @@
package config
import (
"os"
"strconv"
)
type Config struct {
Locale string
Token string
Webhookurl string
Webhooktoken string
PageSize int
CacheTTL int
}
func Load() *Config {
return &Config{
Locale: getEnv("DOCKERBOT_LOCALE", "en"),
Token: getEnv("DOCKERBOT_TOKEN", ""),
Webhookurl: getEnv("DOCKERBOT_WEBHOOKURL", ""),
Webhooktoken: getEnv("DOCKERBOT_WEBHOOK_TOKEN", ""),
PageSize: getEnvInt("DOCKERBOT_PAGE_SIZE", 4),
CacheTTL: getEnvInt("DOCKERBOT_CACHE_TTL", 10),
}
}
func getEnv(key, defaultValue string) string {
val := os.Getenv(key)
if val == "" {
return defaultValue
}
return val
}
func getEnvInt(key string, defaultValue int) int {
valStr := os.Getenv(key)
if valStr == "" {
return defaultValue
}
val, err := strconv.Atoi(valStr)
if err != nil {
return defaultValue
}
if val <= 0 {
return defaultValue
}
return val
}
func getEnvBool(key string, defaultValue bool) bool {
val := os.Getenv(key)
if val == "" {
return defaultValue
}
v, err := strconv.ParseBool(val)
if err != nil {
return defaultValue
}
return v
}