cup/utils/helpers.go

25 lines
724 B
Go
Raw Normal View History

2024-09-12 19:15:38 -04:00
// Copyright 2023 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file.
package utils
import (
"crypto/md5"
"fmt"
2024-12-04 08:39:08 -05:00
"time"
2024-09-12 19:15:38 -04:00
)
// generate a hashed string to be used as key for caching auth jwt token
func CreateAuthTokenHashedCacheKey(userID uint, userAgent string) string {
cacheKey := fmt.Sprintf("userid:_%v_useragent:_%v_jwt_token", userID, userAgent)
hashedCacheKey := fmt.Sprintf("%v", fmt.Sprintf("%x", md5.Sum([]byte(cacheKey))))
return hashedCacheKey
}
2024-12-04 08:39:08 -05:00
func FormatUnix(value int64) string {
return time.Unix(value, 0).Format("2006-01-02 15:04:05")
}