utils

package
v0.0.0-...-9cf9cea Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

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")
)
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 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 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 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 SignURL

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

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 ValidateEmail

func ValidateEmail(email string) error

func ValidateOTP

func ValidateOTP(otp string) error

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 VerifySignedURL

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

Types

type NetworkType

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

func GetNetworkTypeFromNetworkPassphrase

func GetNetworkTypeFromNetworkPassphrase(networkPassphrase string) (NetworkType, 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