config.go raw
1 package main
2
3 import (
4 "os"
5 "strings"
6 "time"
7
8 "go-simpler.org/env"
9 "next.orly.dev/pkg/lol/chk"
10 "next.orly.dev/pkg/lol/log"
11 )
12
13 // Config holds the cluster sync service configuration.
14 type Config struct {
15 // Listen is the gRPC server listen address
16 Listen string `env:"ORLY_SYNC_CLUSTER_LISTEN" default:"127.0.0.1:50062" usage:"gRPC server listen address"`
17
18 // LogLevel is the logging level
19 LogLevel string `env:"ORLY_SYNC_CLUSTER_LOG_LEVEL" default:"info" usage:"log level (trace, debug, info, warn, error)"`
20
21 // Database configuration
22 DBType string `env:"ORLY_SYNC_CLUSTER_DB_TYPE" default:"grpc" usage:"database type: grpc or badger"`
23 GRPCDBServer string `env:"ORLY_SYNC_CLUSTER_DB_SERVER" default:"127.0.0.1:50051" usage:"gRPC database server address"`
24 DataDir string `env:"ORLY_DATA_DIR" usage:"database data directory (for badger mode)"`
25
26 // Cluster configuration
27 AdminNpubsRaw string `env:"ORLY_SYNC_CLUSTER_ADMINS" usage:"comma-separated admin npubs"`
28 PropagatePrivilegedEvents bool `env:"ORLY_SYNC_CLUSTER_PROPAGATE_PRIVILEGED" default:"true" usage:"propagate privileged events (DMs, gift wraps)"`
29 PollInterval time.Duration `env:"ORLY_SYNC_CLUSTER_POLL_INTERVAL" default:"5s" usage:"poll interval"`
30
31 // NIP-11 cache configuration
32 NIP11CacheTTL time.Duration `env:"ORLY_SYNC_CLUSTER_NIP11_TTL" default:"30m" usage:"NIP-11 cache TTL"`
33
34 // Parsed admin npubs
35 AdminNpubs []string
36 }
37
38 // loadConfig loads configuration from environment variables.
39 func loadConfig() *Config {
40 cfg := &Config{}
41 if err := env.Load(cfg, nil); chk.E(err) {
42 log.E.F("failed to load config: %v", err)
43 os.Exit(1)
44 }
45
46 // Parse admin npubs from comma-separated string
47 if cfg.AdminNpubsRaw != "" {
48 cfg.AdminNpubs = strings.Split(cfg.AdminNpubsRaw, ",")
49 for i, p := range cfg.AdminNpubs {
50 cfg.AdminNpubs[i] = strings.TrimSpace(p)
51 }
52 }
53
54 return cfg
55 }
56