...
1 package credentials
2
3 import (
4 "net/http"
5 "time"
6 )
7
8 const defaultInAdvanceScale = 0.95
9
10 var hookDo = func(fn func(req *http.Request) (*http.Response, error)) func(req *http.Request) (*http.Response, error) {
11 return fn
12 }
13
14 type credentialUpdater struct {
15 credentialExpiration int
16 lastUpdateTimestamp int64
17 inAdvanceScale float64
18 }
19
20 func (updater *credentialUpdater) needUpdateCredential() (result bool) {
21 if updater.inAdvanceScale == 0 {
22 updater.inAdvanceScale = defaultInAdvanceScale
23 }
24 return time.Now().Unix()-updater.lastUpdateTimestamp >= int64(float64(updater.credentialExpiration)*updater.inAdvanceScale)
25 }
26
View as plain text