utils

package
v0.10.46 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 25 Imported by: 5

Documentation

Index

Constants

View Source
const (
	TEST_CPF   = "00000000191"
	TEST_TOKEN = "123456"

	// formas de envio de mensagem
	SEND_MEDIA_SMS      = 1
	SEND_MEDIA_EMAIL    = 2
	SEND_MEDIA_WHATSAPP = 3

	PHONENUMBER_MAX_LENGTH  = 9
	PHONENUMBER_MIN_LENGTH  = 8
	FULL_PHONENUMBER_LENGTH = 13

	WHATSAPP_PHONENUMBER_LENGTH = 12

	VALID_EMAIL_REGEX = "" /* 135-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func ByteToMapInterface

func ByteToMapInterface(bytes []byte) map[string]interface{}

Convert a byte sequence to a map[string]string

func ByteToStruct added in v0.7.0

func ByteToStruct(raw []byte, result interface{}) error

Convert a byte sequence to a struct If some error occurs, return the error

func CompleteWithZeros

func CompleteWithZeros(str string, length int) string

Complete a string with left zeros until it reaches the desired length

func DatesInInterval added in v0.10.33

func DatesInInterval(start string, end string) []string

Returns a string list with the dates between the start and end dates, inclusive of both The dates must be in the format "2006-01-02"

func EnhanceSentryEvent added in v0.7.10

func EnhanceSentryEvent(handler http.HandlerFunc) http.HandlerFunc

Encapsulate the handler with Sentry

func ExtractFileFromBase64 added in v0.8.0

func ExtractFileFromBase64(r io.Reader) (*os.File, error)

Extract the file from a base64 string in a slice of bytes The base64 string must be in the format "data:{mimeType};base64,...." The file is saved in a temporary directory and the path is returned The file name is a UUID to avoid conflicts

func ExtractValue

func ExtractValue(key string, jwt string) (interface{}, error)

Extract a value from a token.

func FileCopy added in v0.8.0

func FileCopy(src, dst string) error

func FileExists

func FileExists(path string) bool

Verify if a file or directory exists

func FileExtension added in v0.8.1

func FileExtension(path string) string

func FileMimeType added in v0.8.1

func FileMimeType(path string) string

func FileSize added in v0.8.1

func FileSize(path string) int64

func FileStartFromBase64 added in v0.8.0

func FileStartFromBase64(r io.Reader) (int, error)

func FileToBase64 added in v0.10.34

func FileToBase64(path string) (string, error)

Generate base64 string from a file the string must start with "data:{mimeType};base64," the file is read in chunks of 510 bytes because needs to be multiple of 3

func FormatCPF added in v0.9.0

func FormatCPF(cpf string) (string, error)

func GetBaseDirectory

func GetBaseDirectory(directory string) string

Identify the root directory of the project. The default is the current one. If there is a running test, the root directory is the first one that contains the directory "config" or the first one inside the directory "go".

func GetFiles added in v0.10.38

func GetFiles(path string) []string

Returns a list with the fullpath of all files in a directory

func GetOnlyNumbers

func GetOnlyNumbers(str string) string

Returns all numbers from a string and only the numbers

func HasOnlyNumbers

func HasOnlyNumbers(str string) bool

func Hash256

func Hash256(s string) string

Calculate the SHA256 hash of a string

func Hash256FromBytes added in v0.7.11

func Hash256FromBytes(b []byte) string

Calculate the SHA256 hash of a byte sequence

func HashNumber added in v0.10.41

func HashNumber(source string) string

Calculate a numeric hash of a string

func IntToString added in v0.7.13

func IntToString(in int) string

Convert an int to a string

func InterfaceToInt added in v0.4.1

func InterfaceToInt(incomming interface{}) int

Convert an interface to an int

func MD5 added in v0.7.4

func MD5(filePath string) (string, error)

Calculate the MD5 hash of a file

func ManageError added in v0.7.9

func ManageError(err error) error

Verify if there is an error and, in this case, try to send it to Sentry and return it. If is a running test, the error isn't sent to Sentry.

func MapInterfaceToBytes

func MapInterfaceToBytes(data map[string]interface{}) []byte

Convert a map[string]interface{} to a byte sequence

func MapStringToMapInterface

func MapStringToMapInterface(data map[string]string) map[string]interface{}

Convert a map[string]string to a map[string]interface{}

func MimeTypeFromBase64 added in v0.8.0

func MimeTypeFromBase64(r io.Reader) (string, error)

func ReadFile added in v0.8.0

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

func SHA256 added in v0.8.1

func SHA256(filePath string) (string, error)

Calculate the SHA256 hash of a file

func StringToInt added in v0.4.1

func StringToInt(in string) int

Convert a string to an int

func StructToMapInterface added in v0.5.0

func StructToMapInterface(data interface{}) (map[string]interface{}, error)

Convert a struct to a map[string]interface{} If some error occurs, return nil and the error

func ValidateCPF

func ValidateCPF(cpf string) bool

func ValidateCellphoneNumber

func ValidateCellphoneNumber(phoneNumber string) error

func ValidateDDD

func ValidateDDD(ddd string) bool

func ValidateEmail

func ValidateEmail(email string) bool

func ValidateLandlineNumber

func ValidateLandlineNumber(phoneNumber string) error

func ValidatePhoneNumber

func ValidatePhoneNumber(phoneNumber string) bool

func ValidateTimestamp

func ValidateTimestamp(timestamp string) bool

func ValidateURL added in v0.5.0

func ValidateURL(link string) bool

func ValidateUUID

func ValidateUUID(subject string) bool

func WhatsappNumberToBrazilianPhonenumber added in v0.7.1

func WhatsappNumberToBrazilianPhonenumber(in string) string

Convert a whatsapp number to a brazilian cellphonenumber

Types

type JwtServer

type JwtServer struct {
	Secret string
}

func NewJwtServer

func NewJwtServer(secret string) *JwtServer

func (*JwtServer) Create

func (j *JwtServer) Create(payload map[string]interface{}) (string, error)

Create a token with a given payload.

func (*JwtServer) Parse

func (j *JwtServer) Parse(token string) (map[string]interface{}, error)

Extract the payload from a token. If the token is invalid, return an error.

func (*JwtServer) Valid

func (j *JwtServer) Valid(token string) bool

Validate a token

type JwtServerInterface

type JwtServerInterface interface {
	Valid(token string) bool
	Create(payload map[string]interface{}) (string, error)
	Parse(token string) (map[string]interface{}, error)
}

Jump to

Keyboard shortcuts

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