mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-03 00:36:56 +00:00
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package atproto
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/bluesky-social/indigo/atproto/identity"
|
|
)
|
|
|
|
var (
|
|
// Shared identity directory instance. Lazily initialized on first GetDirectory()
|
|
// call. Tests may swap it out via SetDirectory().
|
|
sharedDirectory identity.Directory
|
|
directoryMu sync.Mutex
|
|
|
|
// testMode allows HTTP did:web resolution (IPs, non-TLS) for local development.
|
|
// Set via SetTestMode() on startup.
|
|
testMode bool
|
|
)
|
|
|
|
// SetTestMode enables relaxed did:web resolution for local development,
|
|
// allowing HTTP and IP-based did:web identifiers that the indigo directory rejects.
|
|
func SetTestMode(enabled bool) {
|
|
testMode = enabled
|
|
}
|
|
|
|
// IsTestMode returns whether test mode is enabled.
|
|
func IsTestMode() bool {
|
|
return testMode
|
|
}
|
|
|
|
// SetDirectory replaces the shared identity.Directory used by all resolver
|
|
// helpers. Intended for tests that wire in a fake directory. Production code
|
|
// should never call this — leaving the default lazy-initialized indigo
|
|
// directory in place via GetDirectory() is correct.
|
|
func SetDirectory(d identity.Directory) {
|
|
directoryMu.Lock()
|
|
defer directoryMu.Unlock()
|
|
sharedDirectory = d
|
|
}
|
|
|
|
// GetDirectory returns the shared identity.Directory. On first call (and if
|
|
// SetDirectory has not been used), it constructs an indigo cached directory
|
|
// with a 24h TTL backed by Jetstream event-driven invalidation.
|
|
//
|
|
// Using a shared instance ensures all identity lookups across the application
|
|
// use the same cache, which is more memory-efficient and provides better cache
|
|
// hit rates.
|
|
func GetDirectory() identity.Directory {
|
|
directoryMu.Lock()
|
|
defer directoryMu.Unlock()
|
|
if sharedDirectory == nil {
|
|
sharedDirectory = identity.DefaultDirectory()
|
|
}
|
|
return sharedDirectory
|
|
}
|