Discover books, shows, and movies at your level. Track your progress by filling your Shelf with what you find, and share with other language learners. *No dusting required. shlf.space
at master 60 lines 1.5 kB view raw
1package atproto 2 3import ( 4 "context" 5 "net" 6 "net/http" 7 "time" 8 9 "github.com/bluesky-social/indigo/atproto/identity" 10 "github.com/bluesky-social/indigo/atproto/syntax" 11 "github.com/carlmjohnson/versioninfo" 12) 13 14type Resolver struct { 15 directory identity.Directory 16} 17 18func DefaultResolver() *Resolver { 19 return &Resolver{ 20 directory: identity.DefaultDirectory(), 21 } 22} 23 24func BaseDirectory() identity.Directory { 25 base := identity.BaseDirectory{ 26 PLCURL: identity.DefaultPLCURL, 27 HTTPClient: http.Client{ 28 Timeout: time.Second * 10, 29 Transport: &http.Transport{ 30 // would want this around 100ms for services doing lots of handle resolution. Impacts PLC connections as well, but not too bad. 31 IdleConnTimeout: time.Millisecond * 1000, 32 MaxIdleConns: 100, 33 }, 34 }, 35 Resolver: net.Resolver{ 36 Dial: func(ctx context.Context, network, address string) (net.Conn, error) { 37 d := net.Dialer{Timeout: time.Second * 3} 38 return d.DialContext(ctx, network, address) 39 }, 40 }, 41 TryAuthoritativeDNS: true, 42 // Primary Bluesky PDS instance only supports HTTP resolution method. 43 SkipDNSDomainSuffixes: []string{".bsky.social"}, 44 UserAgent: "indigo-identity/" + versioninfo.Short(), 45 } 46 return &base 47} 48 49func (r *Resolver) ResolveIdent(ctx context.Context, arg string) (*identity.Identity, error) { 50 id, err := syntax.ParseAtIdentifier(arg) 51 if err != nil { 52 return nil, err 53 } 54 55 return r.directory.Lookup(ctx, id) 56} 57 58func (r *Resolver) Directory() identity.Directory { 59 return r.directory 60}