From fe48c8cb737916936c7530405db2e6049567a203 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Wed, 30 Sep 2020 12:13:37 +0200 Subject: [PATCH] cache ValidateAuthToken --- login.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/login.go b/login.go index 89b17d1..6cacdde 100644 --- a/login.go +++ b/login.go @@ -85,6 +85,17 @@ func (api *API) loginPostHandler(m LoginModel) func(c *gin.Context) { // ValidateAuthToken checks if token is valid and returns its data func (c *Context) ValidateAuthToken() (tokenObject map[string]interface{}, tokenType string, err error) { + + tokenObject = c.GetStringMap("validate-auth-token-object") + if tokenObject != nil { + tokenType = c.GetString("validate-auth-token-type") + _err, _ := c.Get("validate-auth-token-err") + if _err != nil { + err = _err.(error) + } + return // return cached data + } + token := c.Request.Header.Get(c.API.authenticationHeader) if token == "" { return nil, "", errors.New("empty token") @@ -110,5 +121,9 @@ func (c *Context) ValidateAuthToken() (tokenObject map[string]interface{}, token return nil, "", errors.New("token object type is invalid") } + c.Set("validate-auth-token-object", _object) + c.Set("validate-auth-token-type", _type) + c.Set("validate-auth-token-err", err) + return _object, _type, err }