helpers

package
v0.0.0-...-ada6369 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(hashedPassword string, plainPassword string) error

ComparePassword compares the hashed password with the plain password.

Parameters:

  • hashedPassword (string): The hashed password to compare.
  • plainPassword (string): The plain password to compare.

Returns:

  • error: An error if passwords do not match. Returns nil if passwords match.

func ExtractUserIDFromToken

func ExtractUserIDFromToken(token *jwt.Token) (uuid.UUID, error)

ExtractUserIDFromToken extracts user ID from a valid JWT token.

Parameters:

  • token *jwt.Token: Valid JWT token.

Returns:

  • uuid.UUID: User ID extracted from the token.
  • error: An error if user ID extraction fails.

func GenerateAccessToken

func GenerateAccessToken(userID uuid.UUID) (string, error)

GenerateAccessToken generates a new JWT access token.

Parameters:

  • userID (uuid.UUID): User ID for whom to generate the token.

Returns:

  • string: JWT access token.
  • error: An error if token generation fails.

func GenerateActivationToken

func GenerateActivationToken(userID uuid.UUID) (string, error)

GenerateActivationToken generates a new JWT activation token.

func GeneratePasswordResetToken

func GeneratePasswordResetToken(userID uuid.UUID) (string, error)

GeneratePasswordResetToken generates a new JWT password reset token.

func GenerateRefreshToken

func GenerateRefreshToken(userID uuid.UUID) (string, error)

GenerateRefreshToken generates a new JWT refresh token.

Parameters:

  • userID (uuid.UUID): User ID for whom to generate the token.

Returns:

  • string: JWT refresh token.
  • error: An error if token generation fails.

func GetEnv

func GetEnv(env, defaultValue string) string

GetEnv returns the value of an environment variable or a default value if the environment variable is not set. The value is trimmed of leading and trailing whitespace.

Parameters:

  • env (string): The name of the environment variable.
  • defaultValue (string): The default value to return if the environment variable is not set.

Returns:

  • environment (string): The value of the environment variable or the default value.

func GetEnvAsInt

func GetEnvAsInt(env string, defaultValue int) int

GetEnvAsInt returns the value of an environment variable as an integer or a default value if the environment variable is not set or is not a valid integer. The value is trimmed of leading and trailing whitespace.

Parameters:

  • env (string): The name of the environment variable.
  • defaultValue (int): The default value to return if the environment variable is not set or is not a valid integer.

Returns:

  • value (int): The value of the environment variable as an integer or the default value.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes the password using bcrypt.

Parameters:

  • password (string): The password to be hashed.

Returns:

  • string: The hashed password.
  • error: An error if hashing fails.

func NewLogger

func NewLogger() *logrus.Logger

NewLogger creates a new logger and returns it.

Returns:

  • logger (*logrus.Logger): The logger instance.

func VerifyAccessToken

func VerifyAccessToken(tokenString string) (*jwt.Token, error)

VerifyAccessToken verifies the JWT access token.

Parameters:

  • tokenString (string): JWT access token string.

Returns:

  • *jwt.Token: Parsed JWT token if valid.
  • error: An error if token verification fails.

func VerifyActivationToken

func VerifyActivationToken(tokenString string) (*jwt.Token, error)

VerifyActivationToken verifies the JWT activation token.

func VerifyPasswordResetToken

func VerifyPasswordResetToken(tokenString string) (*jwt.Token, error)

VerifyPasswordResetToken verifies the JWT password reset token.

func VerifyRefreshToken

func VerifyRefreshToken(tokenString string) (*jwt.Token, error)

VerifyRefreshToken verifies the JWT refresh token.

Parameters:

  • tokenString (string): JWT refresh token string.

Returns:

  • *jwt.Token: Parsed JWT token if valid.
  • error: An error if token verification fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL