package config import "github.com/spf13/viper" // setDefaults applies the baked-in defaults. Keep in lockstep with // configs/anchorage.example.yaml — the example file should never document // a value that differs silently from these defaults. func setDefaults(v *viper.Viper) { // Server v.SetDefault("server.host", "0.0.0.0") v.SetDefault("server.port", 8080) v.SetDefault("server.readTimeout", "10s") v.SetDefault("server.writeTimeout", "30s") // server.metrics.allowCIDRs intentionally has NO default set via Viper — // nil is how we signal "fall through to metrics.DefaultAllowCIDRs". // Explicit `[]` in YAML → operator-chosen allow-all. v.SetDefault("server.rateLimit.sessionPerMinute", 10) v.SetDefault("server.rateLimit.anonymousPerMinute", 120) // Node — id falls back to OS hostname in applyHostnameFallback. v.SetDefault("node.multiaddrs", []string{}) v.SetDefault("node.stateDir", "/var/lib/anchorage") // IPFS (local paired Kubo) v.SetDefault("ipfs.rpc", "http://localhost:5001") v.SetDefault("ipfs.timeout", "2m") v.SetDefault("ipfs.reconciler.interval", "10m") v.SetDefault("ipfs.reconciler.autoRepair", false) // Cluster — safe single-node defaults; operators bump minReplicas in HA. v.SetDefault("cluster.minReplicas", 1) v.SetDefault("cluster.heartbeatInterval", "5s") v.SetDefault("cluster.downAfter", "30s") v.SetDefault("cluster.rebalanceInterval", "1m") v.SetDefault("cluster.autoRepair", false) v.SetDefault("cluster.drainGracePeriod", "2m") v.SetDefault("cluster.maintenance.maxDuration", "1h") // Postgres v.SetDefault("postgres.maxConns", 20) v.SetDefault("postgres.autoMigrate", true) v.SetDefault("postgres.requeueSweeper", "30s") // NATS v.SetDefault("nats.client.host", "0.0.0.0") v.SetDefault("nats.client.port", 4222) v.SetDefault("nats.cluster.name", "anchorage") v.SetDefault("nats.cluster.host", "0.0.0.0") v.SetDefault("nats.cluster.port", 6222) v.SetDefault("nats.cluster.routes", []string{}) v.SetDefault("nats.jetstream.replicas", 3) // Auth — TTLs only; keys/issuers must be provided by the operator. // // defaultTTL is for interactive / web-session tokens (short). // maxTTL = 395 days (1 year + 30-day grace) accommodates IPFS // client tokens issued to long-lived CLI / CI / service identities // — see `anchorage admin mint-token` for the break-glass path. v.SetDefault("auth.apiToken.defaultTTL", "24h") v.SetDefault("auth.apiToken.maxTTL", "9480h") // Logging — text to stderr by default; file is opt-in. v.SetDefault("logging.level", "info") v.SetDefault("logging.format", "text") v.SetDefault("logging.source", false) v.SetDefault("logging.maxSizeMB", 100) v.SetDefault("logging.maxBackups", 10) v.SetDefault("logging.maxAgeDays", 30) v.SetDefault("logging.compress", true) }