common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: GPL-3.0-or-later Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake converts camelCase to snake_case

func Capitalize

func Capitalize(s string) string

Capitalize capitalizes first letter of string

func ContainsAny

func ContainsAny(s string, substrings []string) bool

ContainsAny checks if string contains any of the substrings

func FormatAmount

func FormatAmount(amount float64, currency string) string

FormatAmount formats monetary amount for display

func FormatAmountWithSeparators

func FormatAmountWithSeparators(amount float64, currency string) string

FormatAmountWithSeparators formats amount with thousands separators

func FormatFileSize

func FormatFileSize(size int64) string

FormatFileSize formats file size in human readable format

func FromJSON

func FromJSON(jsonStr string, v interface{}) error

FromJSON parses JSON string to interface

func GenerateReference

func GenerateReference(prefix string) string

func GenerateSalt

func GenerateSalt(length int) string

GenerateSalt generates a random salt

func GenerateTransactionID

func GenerateTransactionID(prefix string) string

func GetMapBool

func GetMapBool(m map[string]interface{}, key string) bool

GetMapBool safely gets bool value from map

func GetMapFloat

func GetMapFloat(m map[string]interface{}, key string) float64

GetMapFloat safely gets float64 value from map

func GetMapInt

func GetMapInt(m map[string]interface{}, key string) int

GetMapInt safely gets int value from map

func GetMapString

func GetMapString(m map[string]interface{}, key string) string

GetMapString safely gets string value from map

func GetMapValue

func GetMapValue(m map[string]interface{}, key string, defaultValue interface{}) interface{}

GetMapValue safely gets value from map with default

func Hash

func Hash(input string) string

Hash generates SHA256 hash of input

func HashWithSalt

func HashWithSalt(input, salt string) string

HashWithSalt generates SHA256 hash with salt

func IsAlphaNumeric

func IsAlphaNumeric(s string) bool

IsAlphaNumeric checks if string contains only alphanumeric characters

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks if string contains only numeric characters

func IsValidUUID

func IsValidUUID(uuid string) bool

IsValidUUID checks if string is valid UUID

func MapKeys

func MapKeys(m map[string]interface{}) []string

MapKeys returns keys from string map

func ParseAmount

func ParseAmount(amountStr string) (float64, error)

ParseAmount parses amount string to float64

func ParseDuration

func ParseDuration(duration string, fallback time.Duration) time.Duration

ParseDuration parses duration with fallback

func SanitizeString

func SanitizeString(input string) string

SanitizeString removes or replaces potentially dangerous characters

func SliceContains

func SliceContains(slice []string, item string) bool

func SliceUnique

func SliceUnique(slice []string) []string

SliceUnique removes duplicates from slice

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel converts snake_case to camelCase

func TimeElapsed

func TimeElapsed(start time.Time) string

TimeElapsed returns human readable time elapsed

func ToJSON

func ToJSON(v interface{}) string

ToJSON converts interface to JSON string

Types

type DefaultHTTPClient

type DefaultHTTPClient struct {
	// contains filtered or unexported fields
}

DefaultHTTPClient implements HTTPClient using Go's http.Client

func (*DefaultHTTPClient) Do

func (c *DefaultHTTPClient) Do(request *HTTPRequest) (*HTTPResponse, error)

Do executes an HTTP request

type HTTPClient

type HTTPClient interface {
	Do(req *HTTPRequest) (*HTTPResponse, error)
}

HTTPClient defines HTTP client interface

func NewHTTPClient

func NewHTTPClient(config HTTPConfig) HTTPClient

NewHTTPClient creates a new HTTP client

type HTTPConfig

type HTTPConfig struct {
	Timeout         time.Duration
	MaxIdleConns    int
	MaxConnsPerHost int
	UserAgent       string
}

HTTPConfig represents HTTP client configuration

type HTTPRequest

type HTTPRequest struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    []byte
	Timeout time.Duration
}

HTTPRequest represents an HTTP request

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Headers    map[string]string
	Body       []byte
}

HTTPResponse represents an HTTP response

type RetryConfig

type RetryConfig struct {
	MaxAttempts  int           `json:"max_attempts"`
	InitialDelay time.Duration `json:"initial_delay"`
	MaxDelay     time.Duration `json:"max_delay"`
	Multiplier   float64       `json:"multiplier"`
	EnableJitter bool          `json:"enable_jitter"`
}

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns default retry configuration

type RetryExecutor

type RetryExecutor struct {
	// contains filtered or unexported fields
}

RetryExecutor handles retry logic

func NewRetryExecutor

func NewRetryExecutor(config RetryConfig) *RetryExecutor

NewRetryExecutor creates a new retry executor

func (*RetryExecutor) ExecutePayment

ExecutePayment executes a payment function with retry logic

type RetryablePaymentFunc

type RetryablePaymentFunc func() (*types.PaymentResponse, error)

RetryablePaymentFunc represents a payment function that can be retried

Jump to

Keyboard shortcuts

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