(ctx context.Context, c *http.Client, id, secret string)
| 226 | var tokenCacheLock sync.Mutex |
| 227 | |
| 228 | func getTokenCached(ctx context.Context, c *http.Client, id, secret string) (string, error) { |
| 229 | tokenCacheLock.Lock() |
| 230 | defer tokenCacheLock.Unlock() |
| 231 | |
| 232 | key := tokenKey{ |
| 233 | id: id, |
| 234 | secret: secret, |
| 235 | } |
| 236 | |
| 237 | token, ok := tokenCache.Get(key) |
| 238 | if ok && time.Now().Before(token.expireAt.Add(-time.Minute)) { |
| 239 | return token.token, nil |
| 240 | } |
| 241 | |
| 242 | token, err := getToken(ctx, c, id, secret) |
| 243 | if err != nil { |
| 244 | return "", err |
| 245 | } |
| 246 | tokenCache.Add(key, token) |
| 247 | |
| 248 | return token.token, nil |
| 249 | } |
| 250 | |
| 251 | // https://open.dingtalk.com/document/orgapp/obtain-the-access_token-of-an-internal-app |
| 252 | func getToken(ctx context.Context, c *http.Client, id, secret string) (*tokenValue, error) { |
no test coverage detected