A community based topic aggregation platform built on atproto
at main 1.3 kB view raw
1package identity 2 3import ( 4 "database/sql" 5 "net/http" 6 "time" 7) 8 9// Config holds configuration for the identity resolver 10type Config struct { 11 HTTPClient *http.Client 12 PLCURL string 13 CacheTTL time.Duration 14} 15 16// DefaultConfig returns a configuration with sensible defaults 17func DefaultConfig() Config { 18 return Config{ 19 PLCURL: "https://plc.directory", 20 CacheTTL: 24 * time.Hour, // Cache for 24 hours 21 HTTPClient: &http.Client{Timeout: 10 * time.Second}, 22 } 23} 24 25// NewResolver creates a new identity resolver with caching 26func NewResolver(db *sql.DB, config Config) Resolver { 27 // Apply defaults if not set 28 if config.PLCURL == "" { 29 config.PLCURL = "https://plc.directory" 30 } 31 if config.CacheTTL == 0 { 32 config.CacheTTL = 24 * time.Hour 33 } 34 if config.HTTPClient == nil { 35 config.HTTPClient = &http.Client{Timeout: 10 * time.Second} 36 } 37 38 // Create base resolver using Indigo 39 base := newBaseResolver(config.PLCURL, config.HTTPClient) 40 41 // Wrap with caching using PostgreSQL 42 cache := NewPostgresCache(db, config.CacheTTL) 43 caching := newCachingResolver(base, cache) 44 45 // Future: could add rate limiting here if needed 46 // if config.MaxConcurrent > 0 { 47 // return newRateLimitedResolver(caching, config.MaxConcurrent) 48 // } 49 50 return caching 51}