helper

package
v0.0.0-...-400441b Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FAILEDPOSTDATA    = "Failed to POST data"
	FAILEDGETDATA     = "Failed to GET data"
	FAILEDPUTDATA     = "Failed to PUT data"
	FAILEDDELETEDATA  = "Failed to DELETE data"
	SUCCEEDPOSTDATA   = "Succeed to POST data"
	SUCCEEDGETDATA    = "Succeed to GET data"
	SUCCEEDPUTDATA    = "Succeed to PUT data"
	SUCCEEDDELETEDATA = "Succeed to DELETE data"
	UNAUTHORIZED      = "Unauthorized"
	FORBIDDEN         = "Forbidden"
)

Constants for message in HTTP response

Variables

View Source
var (
	// ErrUnsupportedDriver is an error message for unsupported database driver
	ErrUnsupportedDriver = errors.New("unsupported database driver")
	// ErrUnsupportedTokenType is an error message for unsupported token type
	ErrUnsupportedTokenType = errors.New("unsupported token type")
	// ErrDataNotFound is an error message for requested data not found
	ErrDataNotFound = errors.New("data not found")
	// ErrDataAlreadyExists is an error message for unique key constraint violation
	ErrDataAlreadyExists = errors.New("data already exists")
	// ErrUnauthorized is an error message for unauthorized access
	ErrUnauthorized = errors.New("unauthorized")
	// ErrForbidden is an error message for forbidden access
	ErrForbidden = errors.New("forbidden")
	// ErrExpiredToken is an error message for expired token
	ErrExpiredToken = errors.New("token has expired")
	// ErrInvalidToken is an error message for invalid token
	ErrInvalidToken = errors.New("token is invalid")
	// ErrEmptyAuthorizationHeader is an error message for empty authorization header
	ErrEmptyAuthorizationHeader = errors.New("empty authorization header")
	// ErrInvalidAuthorizationHeader is an error message for invalid authorization header
	ErrInvalidAuthorizationHeader = errors.New("invalid authorization header")
	// ErrInvalidAuthorizationType is an error message for invalid authorization type
	ErrInvalidAuthorizationType = errors.New("invalid authorization type")
	// ErrInsufficientPermission is an error message for insufficient permission to access a resource
	ErrInsufficientPermission = errors.New("only admin can access this resource")
)

Error messages

Functions

func ComparePassword

func ComparePassword(password, hashedPassword string) error

ComparePassword compares input password with hashed password

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes input password using bcrypt

func ParseTime

func ParseTime(dateStr string) (time.Time, error)

ParseTime parses a date string into a time.Time object.

func Response

func Response(ctx *fiber.Ctx, code int, status bool, message string, err error, data any) error

Response creates a new instance of JSONResponse.

Types

type JSONResponse

type JSONResponse struct {
	Status  bool     `json:"status"`
	Message string   `json:"message"`
	Errors  []string `json:"errors"`
	Data    any      `json:"data"`
}

Response is a struct for structuring HTTP response in JSON format.

Jump to

Keyboard shortcuts

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