general

package
v0.0.0-...-224d1cc Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package general - contains general functions

Index

Constants

This section is empty.

Variables

View Source
var ValidLanguageNameRegex = regexp.MustCompile("^[a-zA-Z ]{3,70}$")

Functions

func AESCBCPKCS5Decryption

func AESCBCPKCS5Decryption(encryptedMessage, key string) (string, error)

func AESCBCPKCS5Encryption

func AESCBCPKCS5Encryption(message, key string) (string, error)

func AESDecrypt

func AESDecrypt(b64src string, key string) string

AESDecrypt does decryption of base64 encoded AES encrypted data an returns plain string

func AESEncrypt

func AESEncrypt(src, key string) string

AESEncrypt does AES Encryption and return base64

func AmountInWords

func AmountInWords(amount float64) string

AmountInWords returns the amount in words

func CalculateMedian

func CalculateMedian(n []float64) float64

CalculateMedian returns median of numbers

func CheckSupportedFormats

func CheckSupportedFormats(r *http.Request, extensions, contentTypes []string) (multipart.File, string, int, string)

CheckSupportedFormats checks for supported formats and returns file object, extension, error http code and error message if any

func CheckWithinNDays

func CheckWithinNDays(inputDateStr string, n int) bool

CheckWithinNDays takes input string in YYYY-MM-DD format

func CleanAddressLine

func CleanAddressLine(addressLine string) string

CleanAddressLine removes unallowed characters from address

func CleanColumn

func CleanColumn(column string) string

CleanColumn removes unallowed characters from address

func ConvertTimeToTimestamp

func ConvertTimeToTimestamp(time time.Time) int64

func ConvertTimestampToTime

func ConvertTimestampToTime(timestamp int64) time.Time

func DateEqual

func DateEqual(date1, date2 time.Time) bool

func DeleteFileByPath

func DeleteFileByPath(path string) error

func DeprecatedValidateStruct

func DeprecatedValidateStruct(s interface{}) error

ValidateStruct validates the struct and return error if they occur

func FileFromURLtoBase64

func FileFromURLtoBase64(url string) string

FileFromURLtoBase64 retrieves file using url and converts to base64

func FormatCurrency

func FormatCurrency(amount float64, showDecimal bool) string

FormatCurrency returns a formatted string with commas for given amount

func GenerateHashedKey

func GenerateHashedKey(password, key string) []byte

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes generates and returns random bytes of specified size n

func GenerateRandomNumber

func GenerateRandomNumber(n int) (string, error)

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString generates and returns a random alphanumeric string with a start_string (with mixed case) of size n

func GetDifferenceInMonths

func GetDifferenceInMonths(a, b time.Time) int

func GetFilePathFromMultipart

func GetFilePathFromMultipart(file multipart.File) (string, error)

func GetFirstSurName

func GetFirstSurName(name string) (string, string)

GetFirstSurName returns first and last name

func GetInitial

func GetInitial(word string) string

GetInitial returns two letter initials from a word

func GetOnlyAlphaNumSpace

func GetOnlyAlphaNumSpace(input string) string

GetOnlyAlphaNumSpace removes everything except alpha numeric characters and space it also removes extra spaces, and keeps case intact

func GetOnlyAlphaNumUpper

func GetOnlyAlphaNumUpper(input string) string

GetOnlyAlphaNumUpper removes everything except alpha numeric characters and turn to upper case

func GetOnlyAlphaSpace

func GetOnlyAlphaSpace(input string) string

GetOnlyAlphaSpace removes everything except alpha characters and space it also removes extra spaces, and keeps case intact

func GetStringFromTemplate

func GetStringFromTemplate(templateString string, data map[string]interface{}) string

GetStringFromTemplate constructs a string by replacing placeholders using a map and returns it

func GetTimeStampPair

func GetTimeStampPair() (time.Time, string)

GetTimeStampPair returns the current time object as well as YYYY-MM-DD HH:MM:SS.MMMMMM format

func GetTimeStampString

func GetTimeStampString() string

GetTimeStampString returns the current time in YYYY-MM-DD HH:MM:SS.MMMMMM format

func GetUUID

func GetUUID() string

GetUUID generates and returns a new UUID v4 string

func IdentReader

func IdentReader(encoding string, input io.Reader) (io.Reader, error)

IdentReader is used while xml parsing

func InArrInt

func InArrInt(val int, arr []int) bool

InArrInt is func that checks for val in Array of type of int

func InArrStr

func InArrStr(val string, arr []string) bool

InArrStr is func that checks for val in Array of type of string

func IsAlphanumeric

func IsAlphanumeric(input string) bool

func IsFreeMail

func IsFreeMail(email string) bool

IsFreeMail checks whether a given email is from a free service or not

func IsInt

func IsInt(uidParam string) (int, error)

func IsLeapYear

func IsLeapYear(year int) bool

func IsNumber

func IsNumber(s string) bool

IsNumber returns true if all chars in s are digits

func IsStringNumeric

func IsStringNumeric(inputStr string) bool

IsStringNumeric returns if string contains only numbers

func KeepOnlyAlphaSpace

func KeepOnlyAlphaSpace(text string) string

KeepOnlyAlphaSpace removes everything except alphabets and space

func LogTimeDifference

func LogTimeDifference(startTime time.Time)

LogTimeDifference logs the elapsed time

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func RemoveAllSpaces

func RemoveAllSpaces(input string) string

RemoveAllSpaces removes all spaces from a string

func RemoveCountryCode

func RemoveCountryCode(mobile string) string

RemoveCountryCode removes the country code and spaces from input mobile string

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(s []string) []string

RemoveDuplicatesAndEmpty removes duplicate strings from list

func RemoveEmptyElements

func RemoveEmptyElements(s []string) []string

RemoveEmptyElements removes empty values from list

func RemoveExtraSpaces

func RemoveExtraSpaces(input string) string

RemoveExtraSpaces removes excess spaces from a string

func RemoveNonUTF8Bytes

func RemoveNonUTF8Bytes(data []byte) []byte

RemoveNonUTF8Bytes removes bytes that isn't UTF-8 encoded

func RemoveNonUTF8Strings

func RemoveNonUTF8Strings(string string) string

RemoveNonUTF8Strings removes strings that isn't UTF-8 encoded

func SQLInjectionValidation

func SQLInjectionValidation(val string) bool

SQLInjectionValidation return bool if the username if valid, to prevent SQL injection

func StartTime

func StartTime() time.Time

StartTime returns current time

func TimeDifference

func TimeDifference(startTime time.Time) time.Duration

TimeDifference returns elapsed time

func ToSnakeCase

func ToSnakeCase(str string) string

func ValidateAccountNumber

func ValidateAccountNumber(accountNumber string) bool

ValidateAccountNumber checks for valid account number

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates an email

func ValidateGSTIN

func ValidateGSTIN(gstin string) bool

ValidateGSTIN validates input capitalised string for being a valid GSTIN

func ValidateIFSC

func ValidateIFSC(ifsc string) bool

func ValidateName

func ValidateName(name string) bool

func ValidateNonPersonalPAN

func ValidateNonPersonalPAN(pan string) bool

ValidateNonPersonalPAN validates input capitalised string for being a valid PAN

func ValidatePAN

func ValidatePAN(pan string) bool

ValidatePAN validates input capitalised string for being a valid PAN

func ValidatePersonalPAN

func ValidatePersonalPAN(pan string) bool

ValidatePersonalPAN validates input capitalised string for being a valid PAN and if its personal

func ValidatePincode

func ValidatePincode(pincode string) bool

ValidatePincode validates input string for being a valid pincode

func ValidateReferenceID

func ValidateReferenceID(referenceID string) bool

func ValidateURL

func ValidateURL(str string) bool

ValidateURL validates input string for being a valid URL

func ValidateUUID

func ValidateUUID(inputStr string) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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