This commit is contained in:
Dev
2025-09-15 04:02:11 +03:00
commit fc86288f06
24 changed files with 2938 additions and 0 deletions

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

@@ -0,0 +1,59 @@
package config
import (
"fmt"
"os"
"time"
)
type Config struct {
Port string
GitHubToken string
GitHubOwner string
GitHubRepo string
CacheDuration time.Duration
UpdateInterval time.Duration
Theme string
BaseURL string
}
func Load() (*Config, error) {
cfg := &Config{
Port: getEnv("PORT", "8080"),
GitHubToken: getEnv("GITHUB_TOKEN", ""),
GitHubOwner: getEnv("GITHUB_OWNER", ""),
GitHubRepo: getEnv("GITHUB_REPO", ""),
CacheDuration: getDurationEnv("CACHE_DURATION", 15*time.Minute),
UpdateInterval: getDurationEnv("UPDATE_INTERVAL", 5*time.Minute),
Theme: getEnv("DEFAULT_THEME", "light"),
BaseURL: getEnv("BASE_URL", "http://localhost:8080"),
}
if cfg.GitHubToken == "" {
return nil, fmt.Errorf("GITHUB_TOKEN environment variable is required")
}
if cfg.GitHubOwner == "" {
return nil, fmt.Errorf("GITHUB_OWNER environment variable is required")
}
if cfg.GitHubRepo == "" {
return nil, fmt.Errorf("GITHUB_REPO environment variable is required")
}
return cfg, nil
}
func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}
func getDurationEnv(key string, defaultValue time.Duration) time.Duration {
if value := os.Getenv(key); value != "" {
if duration, err := time.ParseDuration(value); err == nil {
return duration
}
}
return defaultValue
}