From 6ab30fc9b66180ace12ecce9369176f0f7e09437 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 21 May 2018 23:06:35 -0500 Subject: [PATCH] lint: duration conv --- app/main.go | 2 +- app/rest/auth/jwt.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/main.go b/app/main.go index df459943..3b86d3d9 100644 --- a/app/main.go +++ b/app/main.go @@ -106,7 +106,7 @@ func main() { RemarkURL: strings.TrimSuffix(opts.RemarkURL, "/"), } - jwtService := auth.NewJWT(opts.SecretKey, strings.HasPrefix(opts.RemarkURL, "https://"), time.Duration(7*24*time.Hour)) + jwtService := auth.NewJWT(opts.SecretKey, strings.HasPrefix(opts.RemarkURL, "https://"), 7*24*time.Hour) srv := api.Rest{ Version: revision, diff --git a/app/rest/auth/jwt.go b/app/rest/auth/jwt.go index 73525435..dc5163d4 100644 --- a/app/rest/auth/jwt.go +++ b/app/rest/auth/jwt.go @@ -120,9 +120,8 @@ func (j *JWT) Refresh(w http.ResponseWriter, r *http.Request) (*CustomClaims, er if err != nil { return nil, err } - untilExp := time.Unix(claims.ExpiresAt, 0).Sub(time.Now()).Seconds() - log.Print(untilExp) - if untilExp < j.exp.Seconds()/2 { + untilExp := claims.ExpiresAt - time.Now().Unix() + if untilExp <= int64(j.exp.Seconds()/2) { claims.ExpiresAt = time.Now().Add(j.exp).Unix() e := j.Set(w, claims) return claims, e