core

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var AccountAliasPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,50}$`)

AccountAliasPattern is the regex pattern for account aliases

View Source
var AssetCodePattern = regexp.MustCompile(`^[A-Z]{3,4}$`)

AssetCodePattern is the regex pattern for asset codes

View Source
var ExternalAccountPattern = regexp.MustCompile(`^@external/([A-Z]{3,4})$`)

ExternalAccountPattern is the regex pattern for external account references

View Source
var TransactionCodePattern = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,100}$`)

TransactionCodePattern is the regex pattern for transaction codes

Functions

func ValidateAccountAlias

func ValidateAccountAlias(alias string) error

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

func ValidateAccountType(accountType string) error

ValidateAccountType validates if the account type is one of the supported types in the Midaz system.

func ValidateAddress

func ValidateAddress(address *Address) error

ValidateAddress validates an address structure for completeness and correctness.

func ValidateAssetCode

func ValidateAssetCode(assetCode string) error

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

func ValidateAssetType(assetType string) error

ValidateAssetType validates if the asset type is one of the supported types in the Midaz system.

func ValidateCountryCode

func ValidateCountryCode(code string) error

ValidateCountryCode checks if the country code is valid according to ISO 3166-1 alpha-2.

func ValidateCurrencyCode

func ValidateCurrencyCode(code string) error

ValidateCurrencyCode checks if the currency code is valid according to ISO 4217.

func ValidateDateRange

func ValidateDateRange(start, end time.Time) error

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

func ValidateMetadata(metadata map[string]any) error

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

func ValidateTransactionCode(code string) error

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

Jump to

Keyboard shortcuts

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