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/ewen-lbh/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} 26 27func LoadConfiguration() (Configuration, error) { 28 if _, err := os.Stat(".env"); err == nil { 29 err := godotenv.Load() 30 if err != nil { 31 ll.ErrorDisplay("could not load .env file", err) 32 } 33 ll.Info("loaded .env file") 34 } 35 36 config := Configuration{} 37 err := env.Parse(&config) 38 if err != nil { 39 return Configuration{}, fmt.Errorf("could not load env variables: %w", err) 40 } 41 42 if config.StartupScheduleRestoration != "enabled" && config.StartupScheduleRestoration != "disabled" && config.StartupScheduleRestoration != "eager" { 43 return Configuration{}, fmt.Errorf("invalid value for STARTUP_SCHEDULE_RESTORATION: %q, should be one of \"enabled\", \"disabled\", \"eager\"", config.StartupScheduleRestoration) 44 } 45 46 ll.Log("Loaded", "green", "configuration from environment") 47 48 return config, nil 49} 50 51var config Configuration 52 53func init() { 54 var err error 55 config, err = LoadConfiguration() 56 if err != nil { 57 panic(fmt.Errorf("could not load configuration: %w", err)) 58 } 59 60 err = setupFirebaseClient() 61 if err != nil { 62 ll.ErrorDisplay("could not setup firebase client", err) 63 } else { 64 ll.Log("Initialized", "cyan", "firebase client") 65 } 66 67 redisClient = redis.NewClient(&redis.Options{ 68 Addr: strings.TrimPrefix(config.RedisURL, "redis://"), 69 }) 70 ll.Log("Initialized", "cyan", "redis client") 71}