utils

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_PROFILE_PICTURE_EXTENSION = ".jpg"
View Source
const MINIMUM_CHARACTERS_FOR_EMAIL = 5
View Source
const MINIMUM_CHARACTERS_FOR_PASSWORD = 16
View Source
const OTP_CHARS = "1234567890"

Variables

This section is empty.

Functions

func ContainsAny

func ContainsAny(str string, chars []string) bool

ContainsAny returns true if the string contains any of the chars

[param] str | string: string to check [param] chars | []string: chars to check

[return] bool: true if the string contains any of the chars

func ContainsNumbers

func ContainsNumbers(str string) bool

ContainsNumbers returns true if the string contains any number

[param] str | string: string to check

[return] bool: true if the string contains any number

func ContainsSpecialCharacters

func ContainsSpecialCharacters(str string) bool

ContainsSpecialCharacters returns true if the string contains any special character

[param] str | string: string to check

[return] bool: true if the string contains any special character

func CreateDir

func CreateDir(path string) error

func CurrentDate

func CurrentDate() string

func DecryptToken

func DecryptToken(token string, secret string) (*jwt.Token, error)

Decrypt a token

[param] token | string | The token

[return] *jwt.Token | The token --> error if something went wrong

func EncryptSha256

func EncryptSha256(text string) string

Encrypt a string using sha256

[param] text | string | The text to encrypt

[return] string | The encrypted text

func ExistsDir

func ExistsDir(path string) bool

func GenerateAuthToken

func GenerateAuthToken(user *models.User, device *models.Device, secret string) (string, error)

Generate a new auth token

[param] user | models.User | The user [param] device | models.Device | The device

[return] string | The token --> error if something went wrong

func GenerateOTP

func GenerateOTP(length int) (string, error)

Generate a random string

[param] length | int | The length of the string

[return] string | The random string --> error if something went wrong

func GenerateValidationCode

func GenerateValidationCode(text string) (string, error)

Generate a validation code

[param] text | string | The text to encrypt

[return] string | The encrypted text

func GetProfilePicturePath

func GetProfilePicturePath(username string, path string) string

func Int2String

func Int2String(num int) string

Convert int to string

[param] num | int: number to convert

[return] string: converted number

func Int642String

func Int642String(num int64) string

Convert Int64 to String

[param] num | int64: number to convert

[return] string: converted number

func IsEmpty

func IsEmpty(str string) bool

IsEmpty returns true if the string is empty

[param] str | string: string to check

[return] bool: true if the string is empty

func IsLowerCase

func IsLowerCase(str string) bool

IsLowerCase returns true if the string is lowercase

[param] str | string: string to check

[return] bool: true if the string is lowercase

func IsUpperCase

func IsUpperCase(str string) bool

IsUpperCase returns true if the string is uppercase

[param] str | string: string to check

[return] bool: true if the string is uppercase

func ReadFile

func ReadFile(filepath string) ([]byte, error)

ReadFile reads a file and returns its content

[param] filepath | string : path to the file [param] content | []byte : content of the file

[return] []byte : content of the file

func SaveFile

func SaveFile(filepath string, content []byte) error

ReadFile reads a file and returns its content

[param] filepath | string : path to the file [param] content | []byte : content of the file

[return] []byte : content of the file

func StringToObjectId

func StringToObjectId(str string) (primitive.ObjectID, error)

StringToObjectId converts a string to a primitive.ObjectID

[param] str | string: string to convert

[return] primitive.ObjectID: converted string

func ValidateDescription

func ValidateDescription(description string) validateResult

Check if the given description string is valid following the next rules:

	[-] At least 8 characters
	[-] At most 500 characters

 [param] description : string: description to check

 [return] the description is valid or not

func ValidateEmail

func ValidateEmail(email string) validateResult

Check if the given email is valid following the next rules:

	[-] At least 5 characters
	[-] At least one @
	[-] At least one .

 [param] email : string: email to check

 [return] the email is valid or not

func ValidateName

func ValidateName(name string) validateResult

Check if the given name string is valid following the next rules:

	[-] At least 2 characters
	[-] At most 50 characters

 [param] name : string: name to check

 [return] the name is valid or not

func ValidatePassword

func ValidatePassword(password string) validateResult

Check if the given password is valid following the next rules:

	[-] At least 16 characters
	[-] At least one special character
	[-] At least one number

 [param] password : string: password to check

 [return] the password is valid or not

func ValueOrEmpty

func ValueOrEmpty(str string) *string

Get string pointer from string or nil if empty

[param] str | string: string to convert

[return] *string: string pointer

Types

This section is empty.

Jump to

Keyboard shortcuts

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