helpers

package
v0.0.0-...-4bc8cf8 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusContinue                      = 100
	StatusSwitchingProtocols            = 101
	StatusProcessing                    = 102
	StatusEarlyHints                    = 103
	StatusOK                            = 200
	StatusCreated                       = 201
	StatusAccepted                      = 202
	StatusNonAuthoritativeInfo          = 203
	StatusNoContent                     = 204
	StatusResetContent                  = 205
	StatusPartialContent                = 206
	StatusMultiStatus                   = 207
	StatusAlreadyReported               = 208
	StatusIMUsed                        = 226
	StatusMultipleChoices               = 300
	StatusMovedPermanently              = 301
	StatusFound                         = 302
	StatusSeeOther                      = 303
	StatusNotModified                   = 304
	StatusUseProxy                      = 305
	StatusTemporaryRedirect             = 307
	StatusPermanentRedirect             = 308
	StatusBadRequest                    = 400
	StatusUnauthorized                  = 401
	StatusPaymentRequired               = 402
	StatusForbidden                     = 403
	StatusNotFound                      = 404
	StatusMethodNotAllowed              = 405
	StatusNotAcceptable                 = 406
	StatusProxyAuthRequired             = 407
	StatusRequestTimeout                = 408
	StatusConflict                      = 409
	StatusGone                          = 410
	StatusLengthRequired                = 411
	StatusPreconditionFailed            = 412
	StatusPayloadTooLarge               = 413
	StatusURITooLong                    = 414
	StatusUnsupportedMediaType          = 415
	StatusRangeNotSatisfiable           = 416
	StatusExpectationFailed             = 417
	StatusTeapot                        = 418
	StatusMisdirectedRequest            = 421
	StatusUnprocessableEntity           = 422
	StatusLocked                        = 423
	StatusFailedDependency              = 424
	StatusUpgradeRequired               = 426
	StatusPreconditionRequired          = 428
	StatusTooManyRequests               = 429
	StatusRequestHeaderFieldsTooLarge   = 431
	StatusUnavailableForLegalReasons    = 451
	StatusInternalServerError           = 500
	StatusNotImplemented                = 501
	StatusBadGateway                    = 502
	StatusServiceUnavailable            = 503
	StatusGatewayTimeout                = 504
	StatusHTTPVersionNotSupported       = 505
	StatusVariantAlsoNegotiates         = 506
	StatusInsufficientStorage           = 507
	StatusLoopDetected                  = 508
	StatusNotExtended                   = 510
	StatusNetworkAuthenticationRequired = 511
)

Define an enum of status codes using constants

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(password string, hash string) (bool, error)

ComparePassword compares a password with a hash

func FormatAPIResponse

func FormatAPIResponse(context *gin.Context, code int, data any)

APIResponse handles the response formatting and error checking

func GetStatusMessage

func GetStatusMessage(code int) string

Function to get message by status code

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a hashed password

func IsEmail

func IsEmail(str string) bool

func SignJWTToken

func SignJWTToken(user models.User) (string, error)

Types

type Claims

type Claims struct {
	ID       primitive.ObjectID `bson:"_id,omitempty"`
	Username string             `json:"username"`
	jwt.RegisteredClaims
}

func ValidateJWTToken

func ValidateJWTToken(signedToken string) (*Claims, error)

ValidateJWTToken parses and validates a JWT token

type HashOptions

type HashOptions struct {
	Rounds   int    // number of bcrypt rounds
	Password string // password to hash or compare
	Hash     string // hash to compare with
}

HashOptions represents options for hashing and comparison

type Response

type Response struct {
	Status   Status      `json:"status"`
	Response interface{} `json:"response"`
}

type Status

type Status struct {
	Code    string `json:"code"`
	Error   bool   `json:"error"`
	Route   string `json:"route"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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