This commit is contained in:
Michael Zhang 2021-07-21 14:55:19 -05:00
parent 47a918a8ef
commit a19ae60600
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -47,10 +47,10 @@ func New(config *config.Config) *Osuapi {
} }
func (api *Osuapi) Token() (token string, err error) { func (api *Osuapi) Token() (token string, err error) {
return api.token(false) return api.tokenFetch(false)
} }
func (api *Osuapi) token(force bool) (token string, err error) { func (api *Osuapi) tokenFetch(force bool) (token string, err error) {
if !force { if !force {
if time.Now().Before(api.expires) { if time.Now().Before(api.expires) {
token = api.token token = api.token
@ -131,7 +131,7 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
if resp.StatusCode == 401 { if resp.StatusCode == 401 {
// force fetch token again // force fetch token again
api.token(true) api.tokenFetch(true)
log.Println("re-fetched token cus expired") log.Println("re-fetched token cus expired")
return api.Request0(action, url) return api.Request0(action, url)
} }