utils

package
v0.0.0-...-c846bbc Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerificationFieldPinMinLength = 4
	VerificationFieldPinMaxLength = 8

	VerificationFieldMaxIdLength = 50
)
View Source
const MaxRetryValue = 32

MaxRetryValue defines the max retry value. We need this to avoid memory overflow.

View Source
const (
	NumberBytes = "0123456789"
)

Variables

View Source
var (
	ErrInvalidECPrivateKey = fmt.Errorf("invalid private key, make sure your private key is generated with a curve at least as strong as prime256v1")
	ErrInvalidECPublicKey  = fmt.Errorf("invalid public key, make sure your public key is generated with a curve at least as strong as prime256v1")
)
View Source
var (
	ErrInvalidBackoffRetryValue = errors.New("invalid backoff retry value")
	ErrMaxRetryValueOverflow    = errors.New("max retry value overflow")
)
View Source
var (
	ErrInvalidE164PhoneNumber = fmt.Errorf("the provided phone number is not a valid E.164 number")
	ErrEmptyPhoneNumber       = fmt.Errorf("phone number cannot be empty")
	ErrEmptyEmail             = fmt.Errorf("email cannot be empty")
)
View Source
var ErrTenantNameNotFound = errors.New("tenant name not found")

Functions

func CalculateExponentialBackoffDuration

func CalculateExponentialBackoffDuration(retry int) (time.Duration, error)

CalculateExponentialBackoffDuration returns exponential value based on the retries in time.Duration.

CalculateExponentialBackoffDuration(1) -> time.Duration(2)
CalculateExponentialBackoffDuration(2) -> time.Duration(4)
CalculateExponentialBackoffDuration(3) -> time.Duration(8)

func ConvertType

func ConvertType[S any, D any](src S) (D, error)

func Decrypt

func Decrypt(message string, passphrase string) (string, error)

Decrypt recovers the original message from a secured one generated by Encrypt.

func Encrypt

func Encrypt(message string, passphrase string) (string, error)

Encrypt secures a message using the AES GCM cipher mode which requires the use of a passphrase for authentication.

func ExponentialBackoffInSeconds

func ExponentialBackoffInSeconds(retry int) (time.Duration, error)

ExponentialBackoffInSeconds returns the duration in seconds based on the number of retries.

func ExtractTenantNameFromHostName

func ExtractTenantNameFromHostName(hostname string) (string, error)

func FloatToString

func FloatToString(inputNum float64) string

FloatToString converts a float number to a string with 7 decimal places.

func GenerateTenantURL

func GenerateTenantURL(baseURL string, tenantID string) (string, error)

func GetRoutePattern

func GetRoutePattern(r *http.Request) string

func GetTypeName

func GetTypeName(v interface{}) string

GetTypeName receives any value and returns the name of its type without the package prefix.

func GetURLWithScheme

func GetURLWithScheme(rawURL string) (string, error)

func Humanize

func Humanize(str string) string

Humanize converts a string to a human readable format.

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to an int

func IsEmpty

func IsEmpty[T any](v T) bool

IsEmpty checks if a value is empty.

func MapSlice

func MapSlice[T any, M any](a []T, f func(T) M) []M

func ParseBoolQueryParam

func ParseBoolQueryParam(r *http.Request, param string) (*bool, error)

ParseBoolQueryParam parses a boolean query parameter from an HTTP request.

func ParseStrongECPrivateKey

func ParseStrongECPrivateKey(privateKeyStr string) (*ecdsa.PrivateKey, error)

ParseStrongECPrivateKey parses a strong elliptic curve private key from a PEM-encoded string. It returns the parsed private key or an error if the key is invalid or not strong enough.

func ParseStrongECPublicKey

func ParseStrongECPublicKey(publicKeyStr string) (*ecdsa.PublicKey, error)

ParseStrongECPublicKey parses a strong elliptic curve public key from a PEM-encoded string. It returns the parsed public key or an error if the key is invalid or not strong enough.

func RandomString

func RandomString(size int, charSetOptions ...string) (string, error)

func SQLNullString

func SQLNullString(s string) sql.NullString

func SignURL

func SignURL(stellarSecretKey string, rawURL string) (string, error)

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a string

func TimePtr

func TimePtr(t time.Time) *time.Time

func TrimAndLower

func TrimAndLower(str string) string

TrimAndLower trims and lowercases a string.

func TruncateString

func TruncateString(str string, borderSizeToKeep int) string

func UnwrapInterfaceToPointer

func UnwrapInterfaceToPointer[T any](i interface{}) *T

UnwrapInterfaceToPointer unwraps an interface to a pointer of the given type.

func ValidateAmount

func ValidateAmount(amount string) error

func ValidateDNS

func ValidateDNS(domain string) error

ValidateDNS will validate the given string as a DNS name.

func ValidateDateOfBirthVerification

func ValidateDateOfBirthVerification(dob string) error

ValidateDateOfBirthVerification will validate the date of birth field for receiver verification.

func ValidateEmail

func ValidateEmail(email string) error

func ValidateNationalIDVerification

func ValidateNationalIDVerification(nationalID string) error

ValidateNationalIDVerification will validate the national id field for receiver verification.

func ValidateNoHTMLNorJSNorCSS

func ValidateNoHTMLNorJSNorCSS(input string) error

ValidateNoHTMLNorJSNorCSS detects HTML, <script> tags, inline JavaScript, and CSS styles in a string

func ValidateOTP

func ValidateOTP(otp string) error

func ValidatePathIsNotTraversal

func ValidatePathIsNotTraversal(p string) error

ValidatePathIsNotTraversal will validate the given path to ensure it does not contain path traversal.

func ValidatePinVerification

func ValidatePinVerification(pin string) error

ValidatePinVerification will validate the pin field for receiver verification.

func ValidateStrongECKeyPair

func ValidateStrongECKeyPair(publicKeyStr, privateKeyStr string) error

ValidateStrongECKeyPair validates if the given public and private keys are a valid EC keypair using a curve that's at least as strong as prime256v1 (P-256).

func ValidateURLScheme

func ValidateURLScheme(link string, scheme ...string) error

ValidateURLScheme checks if a URL is valid and if it has a valid scheme.

func ValidateYearMonthVerification

func ValidateYearMonthVerification(yearMonth string) error

ValidateYearMonthVerification will validate the year/month field for receiver verification.

func VerifySignedURL

func VerifySignedURL(signedURL string, expectedPublicKey string) (bool, error)

func VisualBool

func VisualBool(b bool) string

Types

type DefaultPrivateKeyEncrypter

type DefaultPrivateKeyEncrypter struct{}

func (*DefaultPrivateKeyEncrypter) Decrypt

func (e *DefaultPrivateKeyEncrypter) Decrypt(message, passphrase string) (string, error)

func (*DefaultPrivateKeyEncrypter) Encrypt

func (e *DefaultPrivateKeyEncrypter) Encrypt(message, passphrase string) (string, error)

type NetworkType

type NetworkType string
const (
	PubnetNetworkType  NetworkType = "pubnet"
	TestnetNetworkType NetworkType = "testnet"
)

func AllNetworkTypes

func AllNetworkTypes() []NetworkType

func GetNetworkTypeFromNetworkPassphrase

func GetNetworkTypeFromNetworkPassphrase(networkPassphrase string) (NetworkType, error)

func (NetworkType) IsPubnet

func (n NetworkType) IsPubnet() bool

func (NetworkType) IsTestnet

func (n NetworkType) IsTestnet() bool

func (NetworkType) Validate

func (n NetworkType) Validate() error

type PrivateKeyEncrypter

type PrivateKeyEncrypter interface {
	Encrypt(message string, passphrase string) (string, error)
	Decrypt(message string, passphrase string) (string, error)
}

type PrivateKeyEncrypterMock

type PrivateKeyEncrypterMock struct {
	mock.Mock
}

func NewPrivateKeyEncrypterMock

func NewPrivateKeyEncrypterMock(t testInterface) *PrivateKeyEncrypterMock

func (*PrivateKeyEncrypterMock) Decrypt

func (pke *PrivateKeyEncrypterMock) Decrypt(message, passphrase string) (string, error)

func (*PrivateKeyEncrypterMock) Encrypt

func (pke *PrivateKeyEncrypterMock) Encrypt(message, passphrase string) (string, error)

type ResultWithTotal

type ResultWithTotal struct {
	Total  int
	Result interface{}
}

func NewResultWithTotal

func NewResultWithTotal(total int, result interface{}) *ResultWithTotal

Jump to

Keyboard shortcuts

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