Documentation
¶
Index ¶
- Variables
- func CheckPassword(password string, hashedPassword string) error
- func HashPassword(password string) (string, error)
- func Logger() gin.HandlerFunc
- func RandomInt(min, max int64) int64
- func RandomString(n int) string
- func SortBy(orderBy string, query *gorm.DB) *gorm.DB
- func Transaction(db *gorm.DB, f func(tx *gorm.DB) error) error
- type JWTMaker
- type Pagination
- type Response
- type ResponseStatus
- type TokenMaker
- type TokenPayload
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("tokens is invalid") ErrExpiredToken = errors.New("tokens has expired") )
Different types of error returned by the VerifyToken function
Functions ¶
func CheckPassword ¶
CheckPassword checks if the provided password is correct or not
func HashPassword ¶
HashPassword returns the bcrypt hash of the password
func Logger ¶
func Logger() gin.HandlerFunc
func RandomString ¶
RandomString generates a random string of length n
Types ¶
type JWTMaker ¶
type JWTMaker struct {
// contains filtered or unexported fields
}
JWTMaker is a JSON Web Token maker
func (*JWTMaker) CreateToken ¶
func (maker *JWTMaker) CreateToken(userId int, duration time.Duration) (string, *TokenPayload, error)
CreateToken creates a new tokens for a specific username and duration
func (*JWTMaker) VerifyToken ¶
func (maker *JWTMaker) VerifyToken(token string) (*TokenPayload, error)
VerifyToken checks if the tokens is valid or not
type Pagination ¶
type Response ¶
type Response struct { Status ResponseStatus `json:"status"` Message string `json:"message"` Data any `json:"data"` }
func ResponseData ¶
func ResponseData(status ResponseStatus, message string, data any) *Response
type ResponseStatus ¶
type ResponseStatus string
const ( ResponseStatusSuccess ResponseStatus = "success" ResponseStatusError ResponseStatus = "error" )
type TokenMaker ¶
type TokenMaker interface { // CreateToken creates a new tokens for a specific username and duration CreateToken(userId int, duration time.Duration) (string, *TokenPayload, error) // VerifyToken checks if the tokens is valid or not VerifyToken(token string) (*TokenPayload, error) }
TokenMaker is an interface for managing tokens
func NewJWTMaker ¶
func NewJWTMaker(secretKey string) (TokenMaker, error)
type TokenPayload ¶
type TokenPayload struct { Id uuid.UUID `json:"id"` UserId int `json:"user_id"` IssuedAt time.Time `json:"issued_at"` ExpiredAt time.Time `json:"expired_at"` }
TokenPayload contains the payload data of the tokens
func NewPayload ¶
func NewPayload(userId int, duration time.Duration) (*TokenPayload, error)
NewPayload creates a new tokens payload with a specific username and duration
func (*TokenPayload) Valid ¶
func (payload *TokenPayload) Valid() error
Valid checks if the tokens payload is valid or not
Click to show internal directories.
Click to hide internal directories.