@@ -16,7 +16,7 @@ import (
1616)
1717
1818var configuration = conf .GetConfig ()
19- var connectionsCacheLock sync.Mutex
19+ var ConnectionsCacheLock sync.Mutex
2020
2121const (
2222 errorMsgAuthorizationViolation = "authorization violation"
@@ -35,7 +35,7 @@ type refreshTokenExpiration struct {
3535 RefreshTokenExpiration int64 `json:"refresh_token_expiration"`
3636}
3737
38- var connectionsCache = map [string ]map [string ]Connection {}
38+ var ConnectionsCache = map [string ]map [string ]Connection {}
3939
4040func connect (password , username , connectionToken string , accountId int ) (* memphis.Conn , error ) {
4141 if configuration .USER_PASS_BASED_AUTH {
@@ -103,15 +103,15 @@ func (ah AuthHandler) Authenticate(c *fiber.Ctx) error {
103103
104104 username := strings .ToLower (body .Username )
105105 accountId := strconv .Itoa (int (body .AccountId ))
106- if connectionsCache [accountId ] == nil {
107- connectionsCacheLock .Lock ()
108- connectionsCache [accountId ] = make (map [string ]Connection )
109- connectionsCacheLock .Unlock ()
106+ if ConnectionsCache [accountId ] == nil {
107+ ConnectionsCacheLock .Lock ()
108+ ConnectionsCache [accountId ] = make (map [string ]Connection )
109+ ConnectionsCacheLock .Unlock ()
110110 }
111111
112- connectionsCacheLock .Lock ()
113- connectionsCache [accountId ][username ] = Connection {Connection : conn , ExpirationTime : tokenExpiry }
114- connectionsCacheLock .Unlock ()
112+ ConnectionsCacheLock .Lock ()
113+ ConnectionsCache [accountId ][username ] = Connection {Connection : conn , ExpirationTime : tokenExpiry }
114+ ConnectionsCacheLock .Unlock ()
115115 return c .Status (fiber .StatusOK ).JSON (fiber.Map {
116116 "jwt" : token ,
117117 "expires_in" : tokenExpiry * 60 * 1000 ,
@@ -211,15 +211,15 @@ func (ah AuthHandler) RefreshToken(c *fiber.Ctx) error {
211211 }
212212
213213 accountId = int (accountId )
214- if connectionsCache [strconv .Itoa (int (accountId ))] == nil {
215- connectionsCacheLock .Lock ()
216- connectionsCache [strconv .Itoa (accountId )] = make (map [string ]Connection )
217- connectionsCacheLock .Unlock ()
214+ if ConnectionsCache [strconv .Itoa (int (accountId ))] == nil {
215+ ConnectionsCacheLock .Lock ()
216+ ConnectionsCache [strconv .Itoa (accountId )] = make (map [string ]Connection )
217+ ConnectionsCacheLock .Unlock ()
218218 }
219219
220- connectionsCacheLock .Lock ()
221- connectionsCache [strconv .Itoa (accountId )][username ] = Connection {Connection : conn , ExpirationTime : refreshTokenExpiry }
222- connectionsCacheLock .Unlock ()
220+ ConnectionsCacheLock .Lock ()
221+ ConnectionsCache [strconv .Itoa (accountId )][username ] = Connection {Connection : conn , ExpirationTime : refreshTokenExpiry }
222+ ConnectionsCacheLock .Unlock ()
223223 return c .Status (fiber .StatusOK ).JSON (fiber.Map {
224224 "jwt" : token ,
225225 "expires_in" : tokenExpiry * 60 * 1000 ,
@@ -230,22 +230,22 @@ func (ah AuthHandler) RefreshToken(c *fiber.Ctx) error {
230230
231231func CleanConnectionsCache () {
232232 for range time .Tick (time .Second * 30 ) {
233- for t , tenant := range connectionsCache {
233+ for t , tenant := range ConnectionsCache {
234234 for u , user := range tenant {
235235 currentTime := time .Now ()
236236 unixTimeNow := currentTime .Unix ()
237- conn := connectionsCache [t ][u ].Connection
237+ conn := ConnectionsCache [t ][u ].Connection
238238 if unixTimeNow > int64 (user .ExpirationTime ) {
239239 conn .Close ()
240- connectionsCacheLock .Lock ()
241- delete (connectionsCache [t ], u )
242- connectionsCacheLock .Unlock ()
240+ ConnectionsCacheLock .Lock ()
241+ delete (ConnectionsCache [t ], u )
242+ ConnectionsCacheLock .Unlock ()
243243 }
244244 }
245- if len (connectionsCache [t ]) == 0 {
246- connectionsCacheLock .Lock ()
247- delete (connectionsCache , t )
248- connectionsCacheLock .Unlock ()
245+ if len (ConnectionsCache [t ]) == 0 {
246+ ConnectionsCacheLock .Lock ()
247+ delete (ConnectionsCache , t )
248+ ConnectionsCacheLock .Unlock ()
249249 }
250250 }
251251 }
0 commit comments