Documentation
¶
Index ¶
- Constants
- Variables
- func New(client *http.Client, opts ...Option) *exchanger
- type BatchExchanges
- type ConvOpt
- type ConversionResponse
- type ExchangeRate
- type Exchanger
- type FetchFunc
- type LatestResponse
- type MergeFunc
- type MergeStrategyType
- type Option
- type Options
- type Prior
- type Provider
- type ProviderRespStatus
- type SourceInfo
Constants ¶
View Source
const ( DefaultRequestTimeout = 10 * time.Second DefaultRetryNum = 1 DefaultRetryDuration = 5 * time.Second )
View Source
const ( // ProviderNameECB source name for European central bank ProviderNameECB = "ecb" // ProviderNameRCB source name for the Russia central bank ProviderNameRCB = "rcb" // ProviderNameCAE source name for the UAE central bank ProviderNameCAE = "cae" )
Variables ¶
View Source
var ( ErrConversionRate = errors.New("can not convert") ErrCurrencyNotFound = errors.New("currency symbol is not supported") )
Functions ¶
Types ¶
type BatchExchanges ¶
type BatchExchanges struct { Items map[label.Symbol]map[label.Symbol]ExchangeRate // contains filtered or unexported fields }
type ConversionResponse ¶
type ConversionResponse struct { Date time.Time Value float64 From label.Currency To label.Currency Rate float64 Amount float64 Info []SourceInfo }
func (ConversionResponse) String ¶
func (e ConversionResponse) String() string
type ExchangeRate ¶
type ExchangeRate struct {
// contains filtered or unexported fields
}
func (ExchangeRate) From ¶
func (r ExchangeRate) From() label.Currency
func (ExchangeRate) Rate ¶
func (r ExchangeRate) Rate() float64
func (ExchangeRate) Time ¶
func (r ExchangeRate) Time() time.Time
func (ExchangeRate) To ¶
func (r ExchangeRate) To() label.Currency
type Exchanger ¶
type Exchanger interface { GetExchangeable() []label.Symbol GetLatest() LatestResponse Convert(ctx context.Context, from, to label.Symbol, value float64) (ConversionResponse, error) }
type FetchFunc ¶
type FetchFunc func(ctx context.Context) LatestResponse
type LatestResponse ¶
type LatestResponse struct { Expected []label.Symbol Unreceived []label.Symbol Info []SourceInfo Result []ExchangeRate }
func (LatestResponse) Verify ¶
func (e LatestResponse) Verify() bool
type MergeFunc ¶
type MergeFunc func(*BatchExchanges, []ExchangeRate)
type MergeStrategyType ¶
type MergeStrategyType string
const ( MergeStrategyTypeRace MergeStrategyType = "race" MergeStrategyTypeAverage MergeStrategyType = "average" MergeStrategyTypePriority MergeStrategyType = "priority" )
type Option ¶
type Option func(*exchanger)
func WithAverageMergeStrategy ¶
func WithAverageMergeStrategy() Option
WithAverageMergeStrategy use the merge strategy to calculate the average Value of exchange rates with a large number of providers
func WithMergeFunc ¶
WithMergeFunc set the custom currency merge function
func WithPriorityMergeStrategy ¶
func WithPriorityMergeStrategy() Option
WithPriorityMergeStrategy use a strategy of merging by priority. You can set the priority of each source. You'll get a response based on priorities
func WithRaceMergeStrategy ¶
func WithRaceMergeStrategy() Option
WithRaceMergeStrategy use the "who's the fastest" merger strategy. Duplicate data that came later are discarded
func WithRequestTimeout ¶
WithRequestTimeout set a timeout for source requests
func WithRetryDuration ¶
WithRetryDuration max retry backoff
func WithRetryNum ¶
WithRetryNum set number of repeated requests for data retrieval errors from the source
type ProviderRespStatus ¶
type ProviderRespStatus byte
const ( ProviderRespStatusFailed ProviderRespStatus = iota ProviderRespStatusOK )
type SourceInfo ¶
type SourceInfo struct { Name string Status ProviderRespStatus ErrorMessage string }
Directories
¶
Path | Synopsis |
---|---|
Package internal contains unexported implementation of currency exchange parsing, generator
|
Package internal contains unexported implementation of currency exchange parsing, generator |
Code generated by gocygen.
|
Code generated by gocygen. |
You can add custom sources.
|
You can add custom sources. |
ecb
This is the source of exchange rates from the Central European Bank.
|
This is the source of exchange rates from the Central European Bank. |
tools
|
|
Click to show internal directories.
Click to hide internal directories.