rkex

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExchangeEntryType = "ExchangeEntry"
)

Variables

This section is empty.

Functions

func RegisterEntryYAML

func RegisterEntryYAML(raw []byte) map[string]rkentry.Entry

RegisterEntryYAML create entry from config file

Types

type BootExchange

type BootExchange struct {
	Exchange struct {
		Enabled         bool   `yaml:"enabled" json:"enabled"`
		Name            string `yaml:"name" json:"name"`
		SyncIntervalMin int    `yaml:"syncIntervalMin" json:"syncIntervalMin"`
		BaseUnit        string `yaml:"baseUnit" json:"baseUnit"`
		Static          struct {
			Enabled  bool               `yaml:"enabled" json:"enabled"`
			Currency map[string]float64 `yaml:"currency" json:"currency"`
		} `yaml:"static" json:"static"`
		Provider struct {
			ExchangeRateApi struct {
				Enabled bool   `yaml:"enabled" json:"enabled"`
				ApiKey  string `yaml:"apiKey" json:"apiKey"`
			} `yaml:"exchangeRateApi" json:"exchangeRateApi"`
		} `yaml:"provider" json:"provider"`
	} `yaml:"exchange" json:"exchange"`
}

BootExchange bootstrap entry from config

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry implementation of rkentry.Entry

func GetExchangeEntry added in v0.0.2

func GetExchangeEntry(name string) *Entry

func RegisterEntry

func RegisterEntry(opts ...Option) *Entry

RegisterEntry register with Option

func (*Entry) Bootstrap

func (e *Entry) Bootstrap(ctx context.Context)

Bootstrap entry

func (*Entry) Convert

func (e *Entry) Convert(srcUnit, targetUnit string, srcAmount float64) (float64, bool)

Convert global function which convert with exchange rate in ExRateEntry

func (*Entry) GetCurrency

func (e *Entry) GetCurrency(srcUnit, targetUnit string) (float64, bool)

GetCurrency with source unit and target unit

func (*Entry) GetDescription

func (e *Entry) GetDescription() string

GetDescription returns description of entry

func (*Entry) GetName

func (e *Entry) GetName() string

GetName returns name of entry

func (*Entry) GetType

func (e *Entry) GetType() string

GetType returns type of entry

func (*Entry) Interrupt

func (e *Entry) Interrupt(ctx context.Context)

Interrupt entry

func (*Entry) ListCurrency

func (e *Entry) ListCurrency(srcUnit string) map[string]float64

ListCurrency list all currency info

func (*Entry) MarshalJSON

func (e *Entry) MarshalJSON() ([]byte, error)

MarshalJSON json marshaller

func (*Entry) String

func (e *Entry) String() string

String to string

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON([]byte) error

UnmarshalJSON json unmarshaller

type ExRateApiSyncer

type ExRateApiSyncer struct {
	BaseUnit string
	Token    string
}

ExRateApiSyncer fetch currency info from remote server

func NewExRateApiSyncer

func NewExRateApiSyncer(base, token string) *ExRateApiSyncer

NewExRateApiSyncer create new ExRateApiSyncer

func (*ExRateApiSyncer) GetType

func (e *ExRateApiSyncer) GetType() string

GetType returns type of Syncer

func (*ExRateApiSyncer) Sync

func (e *ExRateApiSyncer) Sync(req *SyncReq) *SyncResp

Sync fetch data from remote server

type Option

type Option func(e *Entry)

Option entry options

func WithBaseUnit

func WithBaseUnit(baseUnit string) Option

WithBaseUnit provide baseUnit.

func WithName

func WithName(name string) Option

func WithSyncIntervalMin

func WithSyncIntervalMin(intervalMin int) Option

WithSyncIntervalMin provide intervalMin.

func WithSyncer

func WithSyncer(in ...Syncer) Option

WithSyncer provide Syncer.

type StaticSyncer

type StaticSyncer struct {
	BaseUnit string
	Currency map[string]float64
}

StaticSyncer stores static currency info defined by user

func NewStaticSyncer

func NewStaticSyncer(base string, cur map[string]float64) *StaticSyncer

NewStaticSyncer create new StaticSyncer

func (*StaticSyncer) GetType

func (s *StaticSyncer) GetType() string

GetType returns type of Syncer

func (*StaticSyncer) Sync

func (s *StaticSyncer) Sync(req *SyncReq) *SyncResp

Sync fetch data from local memory

type SyncReq

type SyncReq struct {
	BaseUnit string
}

SyncReq defines request of Sync()

type SyncResp

type SyncResp struct {
	Meta struct {
		RequestId  string
		Success    bool
		SourceType string
		SyncTime   time.Time
		Error      error
	}
	BaseUnit string
	Currency map[string]float64
}

SyncResp defines response of Sync()

func NewSyncResp

func NewSyncResp(req *SyncReq) *SyncResp

NewSyncResp create new SyncResp based on SyncReq

type Syncer

type Syncer interface {
	GetType() string

	Sync(*SyncReq) *SyncResp
}

Syncer interface

Jump to

Keyboard shortcuts

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