utils

package
v0.0.0-...-149851f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAmounts

func AddAmounts(a, b int64, currency string) (int64, error)

AddAmounts adds two amounts in smallest unit (must be same currency) Returns the sum in smallest unit

func AmountToInt64

func AmountToInt64(amount money.Amount) (int64, error)

AmountToInt64 converts money.Amount to int64 in smallest unit (minor units) Example: AmountToInt64(1000.50 KES) returns 100050 (cents)

func ApplyBasisPoints

func ApplyBasisPoints(smallestUnit int64, bps BasisPoints, currency string) (int64, error)

ApplyBasisPoints applies a basis points percentage to an amount Example: ApplyBasisPoints(100000, 350, "KES") = 3500 (3.5% of 1000.00)

func CalculateCompoundInterest

func CalculateCompoundInterest(principal int64, rateBps BasisPoints, durationDays int, currency string) (int64, error)

CalculateCompoundInterest calculates compound interest with daily compounding Returns the total amount (principal + interest) in smallest unit

func CalculateSimpleInterest

func CalculateSimpleInterest(principal int64, rateBps BasisPoints, durationDays int, currency string) (int64, error)

CalculateSimpleInterest calculates simple interest: I = P * r * t principal: amount in smallest unit rateBps: annual interest rate in basis points durationDays: loan duration in days Returns interest amount in smallest unit

func CompareAmounts

func CompareAmounts(a, b int64, currency string) (int, error)

CompareAmounts compares two amounts in smallest unit (same currency) Returns: -1 if a < b, 0 if a == b, 1 if a > b

func ConvertCurrency

func ConvertCurrency(amount int64, fromCurrency, toCurrency string, exchangeRateBps int64) (int64, error)

ConvertCurrency converts an amount from one currency to another using an exchange rate exchangeRateBps: exchange rate in basis points (e.g., 7700 = 0.77 USD per KES)

func FormatAmount

func FormatAmount(smallestUnit int64, currency string) string

FormatAmount formats an amount in smallest unit to a readable string Example: FormatAmount(100050, "KES") = "KES 1000.50"

func Int64ToAmount

func Int64ToAmount(smallestUnit int64, currency string) (money.Amount, error)

Int64ToAmount converts an amount in smallest unit (int64) to money.Amount Uses minor units (cents, satoshis, etc.) for the specified currency Example: Int64ToAmount(100050, "KES") converts 100050 cents to 1000.50 KES

func IsNegative

func IsNegative(amount int64) bool

IsNegative checks if an amount is negative

func IsPositive

func IsPositive(amount int64) bool

IsPositive checks if an amount is positive

func IsZero

func IsZero(amount int64) bool

IsZero checks if an amount is zero

func MultiplyAmount

func MultiplyAmount(smallestUnit int64, multiplier float64, currency string) (int64, error)

MultiplyAmount multiplies an amount by a factor Example: MultiplyAmount(100000, 2.5, "KES") = 250000 (1000.00 * 2.5 = 2500.00)

func ParseAmount

func ParseAmount(amountStr string, currency string) (int64, error)

ParseAmount parses a string amount to int64 in smallest unit Example: ParseAmount("1000.50", "KES") = 100050 (cents)

func SubtractAmounts

func SubtractAmounts(a, b int64, currency string) (int64, error)

SubtractAmounts subtracts two amounts in smallest unit (must be same currency) Returns a - b in smallest unit

func ValidateCurrency

func ValidateCurrency(currencyCode string) bool

ValidateCurrency checks if a currency code is supported

Types

type BasisPoints

type BasisPoints int32

BasisPoints represents interest rates, fees, and percentages as basis points 1 basis point = 0.01% = 0.0001 Example: 15.00% = 1500 bps, 3.75% = 375 bps, 178.00% = 17800 bps

func ToBps

func ToBps(percentage float64) BasisPoints

ToBps converts a percentage (as float) to basis points Example: ToBps(15.0) = 1500 (15.00%)

func (BasisPoints) String

func (bp BasisPoints) String() string

String returns a formatted percentage string Example: BasisPoints(1500).String() = "15.00%"

func (BasisPoints) ToDecimal

func (bp BasisPoints) ToDecimal() float64

ToDecimal converts basis points to decimal representation for multiplication Example: BasisPoints(1500).ToDecimal() = 0.15

func (BasisPoints) ToPercent

func (bp BasisPoints) ToPercent() float64

ToPercent converts basis points to percentage as float Example: BasisPoints(1500).ToPercent() = 15.0

type PDFParser

type PDFParser struct{}

PDFParser handles PDF document parsing

func NewPDFParser

func NewPDFParser() *PDFParser

NewPDFParser creates a new PDF parser

func (*PDFParser) DecryptPDF

func (p *PDFParser) DecryptPDF(pdfData []byte, password string) ([]byte, error)

DecryptPDF decrypts a password-protected PDF

func (*PDFParser) ExtractText

func (p *PDFParser) ExtractText(pdfData []byte) (string, error)

ExtractText extracts text from PDF

func (*PDFParser) ParseWithPassword

func (p *PDFParser) ParseWithPassword(pdfData []byte, password string) (string, error)

ParseWithPassword attempts to parse a password-protected PDF

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Data       []T `json:"data"`
	Page       int `json:"page"`
	PageSize   int `json:"page_size"`
	TotalCount int `json:"total_count"`
}

PaginatedResponse is a generic paginated response

type Pagination

type Pagination struct {
	Page     int
	PageSize int
}

Pagination is shared across services

Jump to

Keyboard shortcuts

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