helpers

package
v0.0.0-...-d88c766 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SeverityLevels = &Severity{
	PANIC: "PANIC",
	ERROR: "ERROR",
	WARN:  "WARN",
	INFO:  "INFO",
	DEBUG: "DEBUG",
}

Instantiate Severity constants

Functions

func Capitalize

func Capitalize(s string) string

func FilteredSlice

func FilteredSlice[T any](arr []T, test func(T) bool) []T

func FoldSlice

func FoldSlice[T any, U any, R any](slice []T, f func(T, R) R, initial R) R

func FormatPrice

func FormatPrice(price float64, curr string) (string, error)

func GenerateNonce

func GenerateNonce() (string, error)

func GenerateUniqueID

func GenerateUniqueID() uint

func IncreaseHTTPRequestCount

func IncreaseHTTPRequestCount(method, path string, status int)

func MapSlice

func MapSlice[T any, U any](slice []T, f func(T) U) []U

func MustRenderHTML

func MustRenderHTML(page templ.Component) []byte

func NormalizeFloatStrToIntStr

func NormalizeFloatStrToIntStr(number string) string

func ParseNumberString

func ParseNumberString(input string) (int64, error)

func RecordBusinessEvent

func RecordBusinessEvent(eventType string)

RecordBusinessEvent is a helper to record a business event

func RecordDBQueryLatency

func RecordDBQueryLatency(queryType string, start time.Time)

RecordDBQueryLatency is a helper to record database query latency

func RecordHTTPRequestDuration

func RecordHTTPRequestDuration(method, path string, status int, duration float64)

func RenderHTML

func RenderHTML(page templ.Component) ([]byte, error)

func Shuffle

func Shuffle(slice []string)

func SortSlice

func SortSlice[T any](arr []T, less func(a, b T) bool)

Types

type CalculationResults

type CalculationResults struct {
	SID                string            `json:"sid"`
	Price              string            `json:"price"`
	Principal          string            `json:"principal"`
	Rate               string            `json:"rate"`
	RateFreq           string            `json:"rateFreq"`
	Currency           string            `json:"currency"`
	Profit             string            `json:"profit"`
	TotalContributions string            `json:"totalContributions"`
	ContribFreq        string            `json:"contribFreq"`
	FinalBalance       string            `json:"finalBalance"`
	YearResults        []YearCalcResults `json:"yearResults"`
}

CalculationResults stores the final output

func CalculateHISAInvestment

func CalculateHISAInvestment(principal, contribution float64, contributionFreqStr, compoundingFreqStr string, annualInterestRate float64, compoundingYears int, currency string) (CalculationResults, error)

func CalculateInvestment

func CalculateInvestment(sid string,
	stockPrice, dividendYield, expenseRatio, principal, contribution float64,
	contributionFreqStr, dividendFreqStr string, annualPriceIncreasePercent, annualDividendIncreasePercent float64,
	compoundingYears int, payoutMonth int, currency string,
) (CalculationResults, error)

Function to calculate investment results

func DecodeResults

func DecodeResults(encoded string) (CalculationResults, error)

func (CalculationResults) Encoded

func (cr CalculationResults) Encoded() (string, error)

type MonthCalcResults

type MonthCalcResults struct {
	MonthName                  string `json:"monthName"`
	ShareAmount                string `json:"shareAmount"`
	Contributions              string `json:"contributions"`
	MonthlyGainedFromPriceInc  string `json:"monthlyGainedFromPriceIncrease"`
	MonthlyGainedFromDividends string `json:"monthlyGainedFromDividends"`
	MonthlyGain                string `json:"monthlyGain"`
	CumGain                    string `json:"cumGain"`
	Balance                    string `json:"balance"`
	Return                     string `json:"return"`
	DRIP                       string `json:"drip"`
}

MonthCalcResults stores monthly calculations

type Reporter

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

func NewReporter

func NewReporter(filePath string) (*Reporter, error)

func (*Reporter) Close

func (r *Reporter) Close() error

Close the report file

func (*Reporter) Report

func (r *Reporter) Report(level SeverityType, message string) error

Report writes a log entry to the file

type Severity

type Severity struct {
	PANIC SeverityType
	ERROR SeverityType
	WARN  SeverityType
	INFO  SeverityType
	DEBUG SeverityType
}

Structured Severity "enum"

type SeverityType

type SeverityType string

SeverityType defines the type for severity levels

type YearCalcResults

type YearCalcResults struct {
	YearName       string             `json:"yearName"`
	ShareAmount    string             `json:"shareAmount"`
	TotalYearGains string             `json:"totalYearGains"`
	CumGain        string             `json:"cumGain"`
	YoyGrowth      string             `json:"yoyGrowth"`
	TotalGrowth    string             `json:"totalGrowth"`
	Balance        string             `json:"balance"`
	MonthsResults  []MonthCalcResults `json:"monthsResults"`
}

YearCalcResults stores yearly calculations

Jump to

Keyboard shortcuts

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