(ctx context.Context, c *http.Client, corpID, secret string)
| 294 | var notFoundUserCache = expirable.NewLRU[string, time.Time](100, nil, time.Hour*48) |
| 295 | |
| 296 | func getTokenCached(ctx context.Context, c *http.Client, corpID, secret string) (string, error) { |
| 297 | tokenCacheLock.Lock() |
| 298 | defer tokenCacheLock.Unlock() |
| 299 | |
| 300 | key := cacheKey{ |
| 301 | corpID: corpID, |
| 302 | secret: secret, |
| 303 | } |
| 304 | |
| 305 | token, ok := tokenCache.Get(key) |
| 306 | if ok && time.Now().Before(token.expireAt.Add(-time.Minute)) { |
| 307 | return token.token, nil |
| 308 | } |
| 309 | |
| 310 | token, err := getToken(ctx, c, corpID, secret) |
| 311 | if err != nil { |
| 312 | return "", err |
| 313 | } |
| 314 | tokenCache.Add(key, token) |
| 315 | |
| 316 | return token.token, nil |
| 317 | } |
no test coverage detected