// Package bootstrap loads config and owns process lifecycle. package bootstrap import ( "fmt" "os" "time" "gopkg.in/yaml.v3" ) type Config struct { Server ServerConfig `yaml:"server"` ID IDConfig `yaml:"id"` MySQL MySQLConfig `yaml:"mysql"` Redis RedisConfig `yaml:"redis"` TaskPool TaskPoolConfig `yaml:"taskpool"` Deliver DeliverConfig `yaml:"deliver"` Session SessionConfig `yaml:"session"` RateLimit RateLimitConfig `yaml:"rate_limit"` Message MessageConfig `yaml:"message"` } type ServerConfig struct { HTTP HTTPConfig `yaml:"http"` TCP TCPConfig `yaml:"tcp"` } type HTTPConfig struct { Addr string `yaml:"addr"` } type TCPConfig struct { Addr string `yaml:"addr"` ProxyProtocol bool `yaml:"proxy_protocol"` TLS TLSConfig `yaml:"tls"` MaxFrameSize int `yaml:"max_frame_size"` IdleTimeout time.Duration `yaml:"idle_timeout"` KeepAlive time.Duration `yaml:"keepalive"` RecvBuffer int `yaml:"recv_buffer"` SendBuffer int `yaml:"send_buffer"` Multicore bool `yaml:"multicore"` CompressMinSize int `yaml:"compress_min_size"` } type TLSConfig struct { CertFile string `yaml:"cert_file"` KeyFile string `yaml:"key_file"` } type IDConfig struct { SnowflakeWorkerID int64 `yaml:"snowflake_worker_id"` } type MySQLConfig struct { DSN string `yaml:"dsn"` } type RedisConfig struct { Addr string `yaml:"addr"` DeliverQueueKey string `yaml:"deliver_queue_key"` DeliverProcessingKey string `yaml:"deliver_processing_key"` } type TaskPoolConfig struct { Size int `yaml:"size"` Queue int `yaml:"queue"` } type DeliverConfig struct { Workers int `yaml:"workers"` TakeTimeout time.Duration `yaml:"take_timeout"` DoneTTL time.Duration `yaml:"done_ttl"` } type SessionConfig struct { OutboundQueueSize int `yaml:"outbound_queue_size"` } type RateLimitConfig struct { MessagePerSecond int `yaml:"message_per_second"` AuthPerSecond int `yaml:"auth_per_second"` SyncInboxPerMinute int `yaml:"sync_inbox_per_minute"` SyncMessagesPerMinute int `yaml:"sync_messages_per_minute"` HistoryPerMinute int `yaml:"history_per_minute"` } type MessageConfig struct { MaxContentSize int `yaml:"max_content_size"` SyncLimit int `yaml:"sync_limit"` MsgIDExpireMS int64 `yaml:"msgid_expire_ms"` } func Load(path string) (*Config, error) { raw, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("read config: %w", err) } cfg := &Config{} if err := yaml.Unmarshal(raw, cfg); err != nil { return nil, fmt.Errorf("parse config: %w", err) } return cfg, nil }