Documentation
¶
Overview ¶
Package currency provides functionality for working with currency codes and metadata. It includes validation, formatting, and conversion utilities for ISO 4217 currency codes.
Deprecated: This package is deprecated and will be removed in a future release. Please use the money package instead: github.com/amirasaad/fintech/pkg/money
Index ¶
- Constants
- Variables
- func Count() (int, error)
- func CountActive() (int, error)
- func CountLegacy() int
- func InitializeGlobalRegistry(ctx context.Context, redisURL ...string) error
- func IsSupported(code string) bool
- func IsSupportedLegacy(code string) bool
- func IsValidFormat(code string) bool
- func Legacy(code string, meta Meta)
- func ListSupported() ([]string, error)
- func ListSupportedLegacy() []string
- func Register(meta Meta) error
- func Unregister(code string) error
- func UnregisterLegacy(code string) bool
- type Amountdeprecated
- type Codedeprecated
- type Currencydeprecated
- type CurrencyConverterdeprecated
- type Entity
- type Meta
- type Moneydeprecated
- type Registry
- func (cr *Registry) Activate(code string) error
- func (cr *Registry) Count() (int, error)
- func (cr *Registry) CountActive() (int, error)
- func (cr *Registry) Deactivate(code string) error
- func (cr *Registry) Get(code string) (Meta, error)
- func (cr *Registry) GetRegistry() registry.Provider
- func (cr *Registry) IsSupported(code string) bool
- func (cr *Registry) ListAll() ([]Meta, error)
- func (cr *Registry) ListSupported() ([]string, error)
- func (cr *Registry) Register(meta Meta) error
- func (cr *Registry) Search(query string) ([]Meta, error)
- func (cr *Registry) SearchByRegion(region string) ([]Meta, error)
- func (cr *Registry) SetRegistry(reg registry.Provider)
- func (cr *Registry) Unregister(code string) error
- type Validator
Constants ¶
const ( // DefaultCode is the fallback currency code (USD) DefaultCode = "USD" // DefaultDecimals is the default number of decimal places for currencies DefaultDecimals = 2 // MaxDecimals is the maximum number of decimal places allowed MaxDecimals = 18 // MaxSymbolLength is the maximum length for currency symbols MaxSymbolLength = 10 // Default is the default currency code (USD) // Deprecated: Use money.USD from the money package instead Default = USD )
const ( // USD represents US Dollar. // // Deprecated: Use money.USD from the money package instead. USD = money.USD // EUR represents Euro. // // Deprecated: Use money.EUR from the money package instead. EUR = money.EUR // JPY represents Japanese Yen. // // Deprecated: Use money.JPY from the money package instead. JPY = money.JPY // KWD represents Kuwaiti Dinar. // // Deprecated: Use money.KWD from the money package instead. KWD = money.KWD // GBP represents British Pound. // // Deprecated: Use money.GBP from the money package instead. GBP = money.GBP )
Common currency codes for convenience. These are provided for backward compatibility.
Variables ¶
var ( // Deprecated: Use money.ErrInvalidCurrency instead ErrInvalidCode = money.ErrInvalidCurrency ErrUnsupported = errors.New("unsupported currency") ErrInvalidDecimals = errors.New("invalid decimals: must be between 0 and 8") ErrInvalidSymbol = errors.New( "invalid symbol: must not be empty and max 10 characters") ErrCurrencyNotFound = errors.New("currency not found") ErrCurrencyExists = errors.New("currency already exists") )
Common errors
var Get = getCurrencyInternal
Get returns currency metadata for the given code
Functions ¶
func CountActive ¶
func CountLegacy ¶
func CountLegacy() int
func InitializeGlobalRegistry ¶
InitializeGlobalRegistry initializes the global currency registry with optional Redis configuration. If redisURL is provided, it will be used to configure Redis caching. If keyPrefix is provided, it will be used as the Redis key prefix. If redisURL is empty, an in-memory cache will be used.
This function should be called during application startup.
func IsSupported ¶
func IsSupportedLegacy ¶
func IsValidFormat ¶
IsValidFormat returns true if the code is a well-formed ISO 4217 currency code (3 uppercase letters).
func ListSupported ¶
func ListSupportedLegacy ¶
func ListSupportedLegacy() []string
func Unregister ¶
func UnregisterLegacy ¶
Types ¶
type CurrencyConverter
deprecated
added in
v1.3.0
type Entity ¶
type Entity struct {
*registry.BaseEntity
// contains filtered or unexported fields
}
Entity implements the registry.Entity interface Deprecated
type Meta ¶
type Meta struct {
Code string `json:"code"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals int `json:"decimals"`
Country string `json:"country,omitempty"`
Region string `json:"region,omitempty"`
Active bool `json:"active"`
Metadata map[string]string `json:"metadata,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
Meta holds currency-specific metadata Deprecated:
func SearchByRegion ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry provides currency-specific operations using the registry system
func GetGlobalRegistry ¶
func GetGlobalRegistry() *Registry
GetGlobalRegistry returns the global currency registry instance. Make sure to call InitializeGlobalRegistry first to initialize the registry. If the registry is nil, it will attempt lazy initialization with in-memory cache. Panics if initialization fails, as the application cannot function without a currency registry.
func New ¶
New creates a new currency registry with default currencies If redisURL is provided, it will use Redis for caching The function accepts optional parameters in this order: redisURL, keyPrefix
func NewRegistryWithPersistence ¶
func NewRegistryWithPersistence( ctx context.Context, persistencePath string, redisURL ...string, ) (*Registry, error)
NewRegistryWithPersistence creates a currency registry with persistence If redisURL is provided, it will use Redis for caching
func (*Registry) CountActive ¶
CountActive returns the number of active currencies
func (*Registry) Deactivate ¶
Deactivate deactivates a currency
func (*Registry) GetRegistry ¶
GetRegistry returns the underlying registry provider
func (*Registry) IsSupported ¶
IsSupported checks if a currency code is registered and active
func (*Registry) ListSupported ¶
ListSupported returns a list of all supported currency codes
func (*Registry) SearchByRegion ¶
SearchByRegion searches for currencies by region
func (*Registry) SetRegistry ¶ added in v1.2.0
func (*Registry) Unregister ¶
Unregister removes a currency from the registry