diff --git a/cmd/arcade/arcade.go b/cmd/arcade/arcade.go index 0e2f31b..f15c656 100644 --- a/cmd/arcade/arcade.go +++ b/cmd/arcade/arcade.go @@ -24,7 +24,7 @@ func init() { r.Use(gin.Recovery()) r.Use(middleware.NewApiKeyAuth(apiKey)) - r.GET("/tokens", http.NewToken) + r.GET("/tokens", http.GetToken) } // Run arcade on port 1982. diff --git a/pkg/http/token.go b/pkg/http/token.go index be07180..57396c1 100644 --- a/pkg/http/token.go +++ b/pkg/http/token.go @@ -10,18 +10,18 @@ import ( ) var ( - mux sync.Mutex - t time.Time - token string - err error - duration = time.Duration(1 * time.Minute) + mux sync.Mutex + t time.Time + token string + err error + expiration = 1 * time.Minute ) -func NewToken(c *gin.Context) { +func GetToken(c *gin.Context) { mux.Lock() defer mux.Unlock() - if time.Since(t) > duration || token == "" { + if time.Since(t) > expiration || token == "" { token, err = google.NewToken() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})