utils

package
v0.0.0-...-48bfdbc Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERR_EXPIRED_OTP = "expired_otp"
View Source
var ERR_INCORRECT_EMAIL = "incorrect_email"
View Source
var ERR_INCORRECT_OTP = "incorrect_otp"
View Source
var ERR_INVALID_AUTH = "invalid_auth"
View Source
var ERR_INVALID_CREDENTIALS = "invalid_credentials"
View Source
var ERR_INVALID_DATA_TYPE = "invalid_data_type"
View Source
var ERR_INVALID_ENTRY = "invalid_entry"
View Source
var ERR_INVALID_OWNER = "invalid_owner"
View Source
var ERR_INVALID_PAGE = "invalid_page"
View Source
var ERR_INVALID_REQUEST = "invalid_request"
View Source
var ERR_INVALID_TOKEN = "invalid_token"
View Source
var ERR_INVALID_VALUE = "invalid_value"
View Source
var ERR_NETWORK_FAILURE = "network_failure"
View Source
var ERR_NON_EXISTENT = "non_existent"
View Source
var ERR_NOT_ALLOWED = "not_allowed"
View Source
var ERR_SERVER_ERROR = "server_error"
View Source
var ERR_UNAUTHORIZED_USER = "unauthorized_user"

Error codes

View Source
var ERR_UNVERIFIED_USER = "unverified_user"
View Source
var ImageExtensions = map[string]string{
	"image/jpeg":    "jpg",
	"image/png":     "png",
	"image/gif":     "gif",
	"image/bmp":     "bmp",
	"image/webp":    "webp",
	"image/tiff":    "tiff",
	"image/svg+xml": "svg",
}

Functions

func BoolAddr

func BoolAddr(b bool) *bool

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func ConvertStructData

func ConvertStructData(object interface{}, targetStruct interface{}) interface{}

func DateValidator

func DateValidator(fl validator.FieldLevel) bool

Validates if a date has a correct format (ISO8601)

func DistinctField

func DistinctField(fl validator.FieldLevel) bool

func FileTypeValidator

func FileTypeValidator(fl validator.FieldLevel) bool

Validates if a file type is accepted

func GenerateFileUrl

func GenerateFileUrl(key string, folder string, contentType string) string

func GetRandomInt

func GetRandomInt(size int) uint32

Generates a random integer with a specified number of digits

func GetRandomString

func GetRandomString(length int) string

func HashPassword

func HashPassword(password string) string

PASSWORD HASHING

func KeysExistInMap

func KeysExistInMap(keys []string, myMap map[string]interface{}) bool

Check if keys exist in map

func ReactionTypeValidator

func ReactionTypeValidator(fl validator.FieldLevel) bool

Validates if a reaction value is the correct one

func UploadImage

func UploadImage(file *os.File, key string, folder string)

func ValidateUUID

func ValidateUUID(fl validator.FieldLevel) bool

Types

type CustomValidator

type CustomValidator struct{}

CustomValidator is a custom validator that uses "github.com/go-playground/validator/v10"

func Validator

func Validator() *CustomValidator

New creates a new instance of CustomValidator

func (*CustomValidator) Validate

func (cv *CustomValidator) Validate(i interface{}) *ErrorResponse

Validate performs the validation of the given struct

type ErrorResponse

type ErrorResponse struct {
	Status  string             `json:"status"`
	Code    string             `json:"code"`
	Message string             `json:"message"`
	Data    *map[string]string `json:"data,omitempty"`
}

func ParseUUID

func ParseUUID(input string) (*uuid.UUID, *ErrorResponse)

UUID PARSER

func RequestErr

func RequestErr(code string, message string, opts ...map[string]string) ErrorResponse

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (ErrorResponse) Init

func (obj ErrorResponse) Init() ErrorResponse

type SignatureFormat

type SignatureFormat struct {
	PublicId  string `json:"public_id" example:"images/f47ac10b-58cc-4372-a567-0e02b2c3d479"`
	Signature string `json:"signature" example:"e1ba4683fbbf90b75ca22e9f8e545b18c6b24eae"`
	Timestamp int64  `json:"timestamp" example:"1678828200"`
}

func GenerateFileSignature

func GenerateFileSignature(key string, folder string) SignatureFormat

Jump to

Keyboard shortcuts

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