A community based topic aggregation platform built on atproto
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 // PLCURL is the URL of the PLC directory (default: https://plc.directory)
12 PLCURL string
13
14 // CacheTTL is how long to cache resolved identities
15 CacheTTL time.Duration
16
17 // HTTPClient for making HTTP requests (optional, will use default if nil)
18 HTTPClient *http.Client
19}
20
21// DefaultConfig returns a configuration with sensible defaults
22func DefaultConfig() Config {
23 return Config{
24 PLCURL: "https://plc.directory",
25 CacheTTL: 24 * time.Hour, // Cache for 24 hours
26 HTTPClient: &http.Client{Timeout: 10 * time.Second},
27 }
28}
29
30// NewResolver creates a new identity resolver with caching
31func NewResolver(db *sql.DB, config Config) Resolver {
32 // Apply defaults if not set
33 if config.PLCURL == "" {
34 config.PLCURL = "https://plc.directory"
35 }
36 if config.CacheTTL == 0 {
37 config.CacheTTL = 24 * time.Hour
38 }
39 if config.HTTPClient == nil {
40 config.HTTPClient = &http.Client{Timeout: 10 * time.Second}
41 }
42
43 // Create base resolver using Indigo
44 base := newBaseResolver(config.PLCURL, config.HTTPClient)
45
46 // Wrap with caching using PostgreSQL
47 cache := NewPostgresCache(db, config.CacheTTL)
48 caching := newCachingResolver(base, cache)
49
50 // Future: could add rate limiting here if needed
51 // if config.MaxConcurrent > 0 {
52 // return newRateLimitedResolver(caching, config.MaxConcurrent)
53 // }
54
55 return caching
56}