this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

identity: updates from jake review

+21 -20
+2 -2
atproto/identity/basic_catalog.go
··· 88 88 89 89 func (c *BasicCatalog) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Identity, error) { 90 90 handle, err := a.AsHandle() 91 - if err == nil { 91 + if nil == err { // if *not* an error 92 92 return c.LookupHandle(ctx, handle) 93 93 } 94 94 did, err := a.AsDID() 95 - if err == nil { 95 + if nil == err { // if *not* an error 96 96 return c.LookupDID(ctx, did) 97 97 } 98 98 return nil, fmt.Errorf("at-identifier neither a Handle nor a DID")
+11 -9
atproto/identity/cache_catalog.go
··· 52 52 } 53 53 54 54 func (c *CacheCatalog) IsHandleStale(e *HandleEntry) bool { 55 - if e.Err == nil && time.Since(e.Updated) > c.HitTTL { 55 + if nil == e.Err && time.Since(e.Updated) > c.HitTTL { 56 56 return true 57 57 } 58 58 if e.Err != nil && time.Since(e.Updated) > c.ErrTTL { ··· 62 62 } 63 63 64 64 func (c *CacheCatalog) IsIdentityStale(e *IdentityEntry) bool { 65 - if e.Err == nil && time.Since(e.Updated) > c.HitTTL { 65 + if nil == e.Err && time.Since(e.Updated) > c.HitTTL { 66 66 return true 67 67 } 68 68 if e.Err != nil && time.Since(e.Updated) > c.ErrTTL { ··· 107 107 var err error 108 108 var entry *HandleEntry 109 109 c.mutex.RLock() 110 - eObj, ok := c.handleCache[h] 110 + maybeEntry, ok := c.handleCache[h] 111 111 c.mutex.RUnlock() 112 112 113 113 if !ok { ··· 116 116 return "", err 117 117 } 118 118 } else { 119 - entry = &eObj 119 + entry = &maybeEntry 120 120 } 121 121 if c.IsHandleStale(entry) { 122 122 entry, err = c.updateHandle(ctx, h) ··· 129 129 130 130 func (c *CacheCatalog) updateDID(ctx context.Context, did syntax.DID) (*IdentityEntry, error) { 131 131 ident, err := c.Inner.LookupDID(ctx, did) 132 + // persist the identity lookup error, instead of processing it immediately 132 133 entry := IdentityEntry{ 133 134 Updated: time.Now(), 134 135 Identity: ident, 135 136 Err: err, 136 137 } 137 138 var he *HandleEntry 138 - if err == nil && !ident.Handle.IsInvalidHandle() { 139 + // if *not* an error, then also update the handle cache 140 + if nil == err && !ident.Handle.IsInvalidHandle() { 139 141 he = &HandleEntry{ 140 142 Updated: time.Now(), 141 143 DID: did, ··· 156 158 var err error 157 159 var entry *IdentityEntry 158 160 c.mutex.RLock() 159 - eObj, ok := c.identityCache[did] 161 + maybeEntry, ok := c.identityCache[did] 160 162 c.mutex.RUnlock() 161 163 162 164 if !ok { ··· 165 167 return nil, err 166 168 } 167 169 } else { 168 - entry = &eObj 170 + entry = &maybeEntry 169 171 } 170 172 if c.IsIdentityStale(entry) { 171 173 entry, err = c.updateDID(ctx, did) ··· 198 200 199 201 func (c *CacheCatalog) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Identity, error) { 200 202 handle, err := a.AsHandle() 201 - if err == nil { 203 + if nil == err { // if not an error, is a handle 202 204 return c.LookupHandle(ctx, handle) 203 205 } 204 206 did, err := a.AsDID() 205 - if err == nil { 207 + if nil == err { // if not an error, is a DID 206 208 return c.LookupDID(ctx, did) 207 209 } 208 210 return nil, fmt.Errorf("at-identifier neither a Handle nor a DID")
+4 -4
atproto/identity/did.go
··· 69 69 if err != nil { 70 70 return nil, fmt.Errorf("failed HTTP fetch of did:web well-known document: %w", err) 71 71 } 72 - if resp.StatusCode == 404 { 72 + if resp.StatusCode == http.StatusNotFound { 73 73 return nil, ErrDIDNotFound 74 74 } 75 - if resp.StatusCode != 200 { 75 + if resp.StatusCode != http.StatusOK { 76 76 return nil, fmt.Errorf("failed did:web well-known fetch, HTTP status: %d", resp.StatusCode) 77 77 } 78 78 ··· 93 93 if err != nil { 94 94 return nil, fmt.Errorf("failed did:plc directory resolution: %w", err) 95 95 } 96 - if resp.StatusCode == 404 { 96 + if resp.StatusCode == http.StatusNotFound { 97 97 return nil, ErrDIDNotFound 98 98 } 99 - if resp.StatusCode != 200 { 99 + if resp.StatusCode != http.StatusOK { 100 100 return nil, fmt.Errorf("failed did:web well-known fetch, HTTP status: %d", resp.StatusCode) 101 101 } 102 102
+2 -3
atproto/identity/handle.go
··· 47 47 // TODO: could pull a client or transport from context? 48 48 c := http.DefaultClient 49 49 50 - req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/.well-known/atproto-did", handle), nil) 50 + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s/.well-known/atproto-did", handle), nil) 51 51 if err != nil { 52 52 return "", err 53 53 } 54 - req = req.WithContext(ctx) 55 54 56 55 resp, err := c.Do(req) 57 56 if err != nil { ··· 64 63 } 65 64 return "", fmt.Errorf("failed to resolve handle (%s) through HTTP well-known route: %s", handle, err) 66 65 } 67 - if resp.StatusCode != 200 { 66 + if resp.StatusCode != http.StatusOK { 68 67 return "", fmt.Errorf("failed to resolve handle (%s) through HTTP well-known route: status=%d", handle, resp.StatusCode) 69 68 } 70 69
+2 -2
atproto/identity/mock_catalog.go
··· 52 52 53 53 func (c *MockCatalog) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Identity, error) { 54 54 handle, err := a.AsHandle() 55 - if err == nil { 55 + if nil == err { // if not an error, is a Handle 56 56 return c.LookupHandle(ctx, handle) 57 57 } 58 58 did, err := a.AsDID() 59 - if err == nil { 59 + if nil == err { // if not an error, is a DID 60 60 return c.LookupDID(ctx, did) 61 61 } 62 62 return nil, fmt.Errorf("at-identifier neither a Handle nor a DID")