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

Function getTokenCached

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

Source from the content-addressed store, hash-verified

144}()
145
146func getTokenCached(ctx context.Context, c *http.Client, id, secret string) (string, error) {
147 tokenCacheLock.Lock()
148 defer tokenCacheLock.Unlock()
149
150 key := tokenKey{
151 id: id,
152 secret: secret,
153 }
154
155 token, ok := tokenCache.Get(key)
156 if ok && time.Now().Before(token.expireAt.Add(-time.Minute)) {
157 return token.token, nil
158 }
159
160 token, err := getToken(ctx, c, id, secret)
161 if err != nil {
162 return "", err
163 }
164 tokenCache.Add(key, token)
165
166 return token.token, nil
167}
168
169func (p *provider) refreshToken(ctx context.Context) error {
170 token, err := getTokenCached(ctx, p.c, p.id, p.secret)

Callers 1

refreshTokenMethod · 0.70

Calls 2

GetMethod · 0.80
getTokenFunction · 0.70

Tested by

no test coverage detected