MCPcopy Create free account
hub / github.com/bytebase/bytebase / getTokenCached

Function getTokenCached

backend/plugin/webhook/dingtalk/app.go:228–249  ·  view source on GitHub ↗
(ctx context.Context, c *http.Client, id, secret string)

Source from the content-addressed store, hash-verified

226var tokenCacheLock sync.Mutex
227
228func 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
252func getToken(ctx context.Context, c *http.Client, id, secret string) (*tokenValue, error) {

Callers 1

refreshTokenMethod · 0.70

Calls 2

GetMethod · 0.80
getTokenFunction · 0.70

Tested by

no test coverage detected