This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

1package notella 2 3import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/caarlos0/env/v11" 9 ll "github.com/gwennlbh/label-logger-go" 10 "github.com/joho/godotenv" 11 "github.com/redis/go-redis/v9" 12) 13 14type Configuration struct { 15 ChurrosDatabaseURL string `env:"DATABASE_URL"` 16 RedisURL string `env:"REDIS_URL"` 17 NatsURL string `env:"NATS_URL" envDefault:"nats://localhost:4222"` 18 VapidPublicKey string `env:"PUBLIC_VAPID_KEY"` 19 VapidPrivateKey string `env:"VAPID_PRIVATE_KEY"` 20 ContactEmail string `env:"CONTACT_EMAIL"` 21 FirebaseServiceAccount string `env:"FIREBASE_SERVICE_ACCOUNT"` 22 StartupScheduleRestoration string `env:"STARTUP_SCHEDULE_RESTORATION" envDefault:"enabled"` 23 AppPackageId string `env:"APP_PACKAGE_ID" envDefault:"app.churros"` 24 HealthCheckPort int `env:"HEALTH_CHECK_PORT" envDefault:"8080"` 25 DryRunMode bool `env:"DRY_RUN" envDefault:"false"` 26 DryRunExceptions []string `env:"DRY_RUN_EXCEPTIONS"` 27} 28 29func LoadConfiguration() (Configuration, error) { 30 if _, err := os.Stat(".env"); err == nil { 31 err := godotenv.Load() 32 if err != nil { 33 ll.ErrorDisplay("could not load .env file", err) 34 } 35 ll.Info("loaded .env file") 36 } 37 38 config := Configuration{} 39 err := env.Parse(&config) 40 if err != nil { 41 return Configuration{}, fmt.Errorf("could not load env variables: %w", err) 42 } 43 44 if config.StartupScheduleRestoration != "enabled" && config.StartupScheduleRestoration != "disabled" && config.StartupScheduleRestoration != "eager" { 45 return Configuration{}, fmt.Errorf("invalid value for STARTUP_SCHEDULE_RESTORATION: %q, should be one of \"enabled\", \"disabled\", \"eager\"", config.StartupScheduleRestoration) 46 } 47 48 ll.Log("Loaded", "green", "configuration from environment") 49 50 return config, nil 51} 52 53var config Configuration 54 55func init() { 56 var err error 57 config, err = LoadConfiguration() 58 if err != nil { 59 panic(fmt.Errorf("could not load configuration: %w", err)) 60 } 61 62 err = setupFirebaseClient() 63 if err != nil { 64 ll.ErrorDisplay("could not setup firebase client", err) 65 } else { 66 ll.Log("Initialized", "cyan", "firebase client") 67 } 68 69 redisClient = redis.NewClient(&redis.Options{ 70 Addr: strings.TrimPrefix(config.RedisURL, "redis://"), 71 }) 72 ll.Log("Initialized", "cyan", "redis client") 73}