Documentation
¶
Overview ¶
Package core provides fundamental validation utilities for the Midaz SDK.
This package contains primitive validation functions that don't depend on any model structures, making it usable by both the models package and the validation package without creating circular dependencies.
Index ¶
- Variables
- func ValidateAccountAlias(alias string) error
- func ValidateAccountType(accountType string) error
- func ValidateAddress(address *Address) error
- func ValidateAssetCode(assetCode string) error
- func ValidateAssetType(assetType string) error
- func ValidateCountryCode(code string) error
- func ValidateCurrencyCode(code string) error
- func ValidateDateRange(start, end time.Time) error
- func ValidateMetadata(metadata map[string]any) error
- func ValidateTransactionCode(code string) error
- type Address
- type ValidationConfig
- type ValidationOption
- func WithMaxAddressLineLength(length int) ValidationOption
- func WithMaxCityLength(length int) ValidationOption
- func WithMaxMetadataSize(size int) ValidationOption
- func WithMaxStateLength(length int) ValidationOption
- func WithMaxStringLength(length int) ValidationOption
- func WithMaxZipCodeLength(length int) ValidationOption
- func WithStrictMode(strict bool) ValidationOption
Constants ¶
This section is empty.
Variables ¶
var AccountAliasPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,50}$`)
AccountAliasPattern is the regex pattern for account aliases
var AssetCodePattern = regexp.MustCompile(`^[A-Z]{3,4}$`)
AssetCodePattern is the regex pattern for asset codes
var ExternalAccountPattern = regexp.MustCompile(`^@external/([A-Z]{3,4})$`)
ExternalAccountPattern is the regex pattern for external account references
var TransactionCodePattern = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,100}$`)
TransactionCodePattern is the regex pattern for transaction codes
Functions ¶
func ValidateAccountAlias ¶
ValidateAccountAlias checks if an account alias is valid. Account aliases should be alphanumeric with optional underscores and hyphens.
Example:
if err := core.ValidateAccountAlias("savings_account"); err != nil {
log.Fatal(err)
}
func ValidateAccountType ¶
ValidateAccountType validates if the account type is one of the supported types in the Midaz system.
func ValidateAddress ¶
ValidateAddress validates an address structure for completeness and correctness.
func ValidateAssetCode ¶
ValidateAssetCode checks if an asset code is valid. Asset codes should be 3-4 uppercase letters (e.g., USD, EUR, BTC).
Example:
if err := core.ValidateAssetCode("USD"); err != nil {
log.Fatal(err)
}
func ValidateAssetType ¶
ValidateAssetType validates if the asset type is one of the supported types in the Midaz system.
func ValidateCountryCode ¶
ValidateCountryCode checks if the country code is valid according to ISO 3166-1 alpha-2.
func ValidateCurrencyCode ¶
ValidateCurrencyCode checks if the currency code is valid according to ISO 4217.
func ValidateDateRange ¶
ValidateDateRange checks if a date range is valid. The start date must not be after the end date.
Example:
start := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2023, 12, 31, 0, 0, 0, 0, time.UTC)
if err := core.ValidateDateRange(start, end); err != nil {
log.Fatal(err)
}
func ValidateMetadata ¶
ValidateMetadata checks if transaction metadata is valid. This function verifies that metadata values are of supported types.
Example:
metadata := map[string]any{
"reference": "inv123",
"amount": 100.50,
"customer_id": 12345,
}
if err := core.ValidateMetadata(metadata); err != nil {
log.Fatal(err)
}
func ValidateTransactionCode ¶
ValidateTransactionCode checks if a transaction code is valid. Transaction codes should be alphanumeric with optional underscores and hyphens.
Example:
if err := core.ValidateTransactionCode("TX_123456"); err != nil {
log.Fatal(err)
}
Types ¶
type Address ¶
type Address struct {
Line1 string
Line2 *string
ZipCode string
City string
State string
Country string
}
Address is a simplified address structure for validation purposes.
type ValidationConfig ¶
type ValidationConfig struct {
// MaxMetadataSize defines the maximum size of metadata in bytes
MaxMetadataSize int
// MaxStringLength defines the maximum length for string fields in metadata
MaxStringLength int
// MaxAddressLineLength defines the maximum length for address lines
MaxAddressLineLength int
// MaxZipCodeLength defines the maximum length for zip codes
MaxZipCodeLength int
// MaxCityLength defines the maximum length for city names
MaxCityLength int
// MaxStateLength defines the maximum length for state names
MaxStateLength int
// StrictMode enables or disables additional validation checks
StrictMode bool
}
ValidationConfig represents options for the validation behavior
func DefaultValidationConfig ¶
func DefaultValidationConfig() *ValidationConfig
DefaultValidationConfig returns a config with default values
func NewValidationConfig ¶
func NewValidationConfig(options ...ValidationOption) (*ValidationConfig, error)
NewValidationConfig creates a validation config with the provided options
type ValidationOption ¶
type ValidationOption func(*ValidationConfig) error
ValidationOption is a function type for configuring a ValidationConfig
func WithMaxAddressLineLength ¶
func WithMaxAddressLineLength(length int) ValidationOption
WithMaxAddressLineLength sets the maximum length for address lines
func WithMaxCityLength ¶
func WithMaxCityLength(length int) ValidationOption
WithMaxCityLength sets the maximum length for city names
func WithMaxMetadataSize ¶
func WithMaxMetadataSize(size int) ValidationOption
WithMaxMetadataSize sets the maximum size for metadata
func WithMaxStateLength ¶
func WithMaxStateLength(length int) ValidationOption
WithMaxStateLength sets the maximum length for state names
func WithMaxStringLength ¶
func WithMaxStringLength(length int) ValidationOption
WithMaxStringLength sets the maximum length for string fields in metadata
func WithMaxZipCodeLength ¶
func WithMaxZipCodeLength(length int) ValidationOption
WithMaxZipCodeLength sets the maximum length for zip codes
func WithStrictMode ¶
func WithStrictMode(strict bool) ValidationOption
WithStrictMode enables or disables strict validation mode