init: initial commit
Checks / verify (push) Canceled after 41s

This commit is contained in:
2026-10-06 11:24:02 +08:00
parent 456e87d4f2
commit ba6dfffab7
63 changed files with 7223 additions and 0 deletions
@@ -0,0 +1,35 @@
package domain
import (
"fmt"
"regexp"
"strconv"
"strings"
"veyra/services/api/internal/platform/apperror"
)
var moneyPattern = regexp.MustCompile(`^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$`)
// ParseMoney converts decimal text into exact cents, rejecting rounding and exponents.
func ParseMoney(value string) (int64, error) {
if !moneyPattern.MatchString(value) {
return 0, apperror.ErrInvalidInput
}
whole, fraction, _ := strings.Cut(value, ".")
units, err := strconv.ParseInt(whole, 10, 64)
if err != nil {
return 0, apperror.ErrInvalidInput
}
fraction += strings.Repeat("0", 2-len(fraction))
cents, err := strconv.ParseInt(fraction, 10, 64)
if err != nil {
return 0, apperror.ErrInvalidInput
}
amount := units*100 + cents
if amount > 100000000000 {
return 0, apperror.ErrInvalidInput
}
return amount, nil
}
func FormatMoney(minor int64) string { return fmt.Sprintf("%d.%02d", minor/100, minor%100) }