feat: CR login, register, subscribe
This commit is contained in:
@@ -8,8 +8,20 @@ type ErrorCode struct {
|
||||
HttpCode int
|
||||
}
|
||||
|
||||
func (e ErrorCode) Error() string {
|
||||
return e.Code
|
||||
}
|
||||
|
||||
var (
|
||||
// 4xx
|
||||
ErrBadRequest = ErrorCode{Code: "BAD_REQUEST", Message: "BAD_REQUEST", HttpCode: http.StatusBadRequest}
|
||||
ErrDBRequest = ErrorCode{Code: "BAD_DB_REQUEST", Message: "DB_ERROR", HttpCode: http.StatusBadRequest}
|
||||
ErrBadRequest = &ErrorCode{Code: "BAD_REQUEST", Message: "BAD_REQUEST", HttpCode: http.StatusBadRequest}
|
||||
ErrDBRequest = &ErrorCode{Code: "BAD_DB_REQUEST", Message: "DB_ERROR", HttpCode: http.StatusBadRequest}
|
||||
|
||||
// 5xx
|
||||
ErrMarshal = &ErrorCode{Code: "FAILED_MARSHAL", Message: "FAILED_MARSHAL_BODY", HttpCode: http.StatusInternalServerError}
|
||||
ErrCreateEntity = &ErrorCode{Code: "FAILED_CREATE_ENTITY", Message: "FAILED_CREATE_ENTITY", HttpCode: http.StatusInternalServerError}
|
||||
|
||||
// redis
|
||||
ErrRedisConnNotFound = &ErrorCode{Code: "FAILED_CONNECT_REDIS", Message: "REDIS_NOT_FOUND", HttpCode: http.StatusInternalServerError}
|
||||
ErrRedisSet = &ErrorCode{Code: "FAILED_SET_REDIS", Message: "FAILED_CACHING", HttpCode: http.StatusInternalServerError}
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"time"
|
||||
|
||||
jwtclaimenum "github.com/ardeman/project-legalgo-go/internal/enums/jwt"
|
||||
timeutils "github.com/ardeman/project-legalgo-go/internal/utilities/time_utils"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
@@ -12,23 +11,23 @@ var jwtSecret = []byte("secret jwt key") // TODO: change later from env
|
||||
|
||||
type ClaimOption func(options jwt.MapClaims)
|
||||
|
||||
func GenerateToken(options ...ClaimOption) (string, error) {
|
||||
now := timeutils.Now()
|
||||
// func GenerateToken(options ...ClaimOption) (string, error) {
|
||||
// now := timeutils.Now()
|
||||
|
||||
claims := jwt.MapClaims{
|
||||
string(jwtclaimenum.ISSUED_AT): now.Unix(),
|
||||
}
|
||||
// claims := jwt.MapClaims{
|
||||
// string(jwtclaimenum.ISSUED_AT): now.Unix(),
|
||||
// }
|
||||
|
||||
for _, o := range options {
|
||||
o(claims)
|
||||
}
|
||||
// for _, o := range options {
|
||||
// o(claims)
|
||||
// }
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
// token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
return token.SignedString(jwtSecret)
|
||||
}
|
||||
// return token.SignedString(jwtSecret)
|
||||
// }
|
||||
|
||||
func GenerateToken2(email string) (string, error) {
|
||||
func GenerateToken(email string) (string, error) {
|
||||
now := timeutils.Now()
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
|
||||
Reference in New Issue
Block a user