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