model

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	// Error code
	Code int `json:"code"`

	// Error message
	Info string `json:"info"`
}

ApiError represents error in API

type ApplicationConfig

type ApplicationConfig struct {
	// HTTP server (Gin) settings
	Engine EngineConfig `yaml:"engine"`

	// Collector settings
	Collector struct {
		// Number of parallel parser workers
		Parallelism int `yaml:"parallelism" env:"COLLECTOR_PARALLELISM" env-default:4`

		// Delay between requests of provider API
		RandomDelay int `yaml:"random_delay" env:"COLLECTOR_DELAY" env-default:1`
	} `yaml:"collector"`

	// Level-1 cache settings (go-cache)
	L1Cache struct {
		// Cache TTL
		DefaultExpiration int `yaml:"default_expiration" env:"L1_DEFAULT_EXPIRATION" env-default:30`

		// Cache cleanup interval (gc calling timeout)
		CleanupInterval int `yaml:"cleanup_interval" env:"L1_CLEANUP_INTERVAL" env-default:60`
	} `yaml:"l1_cache"`

	// Level-2 cache settings (MySQL)
	L2Cache struct {
		// Database server hostname
		Hostname string `yaml:"hostname" env:"L2_HOSTNAME" env-default:"127.0.0.1"`

		// Database server port
		Port int `yaml:"port" env:"L2_PORT" env-default:3306`

		// Database server username
		Username string `yaml:"username" env:"L2_USERNAME"`

		// Database server password
		Password string `yaml:"password" env:"L2_PASSWORD"`

		// Database server database name
		Database string `yaml:"database" env:"L2_DATABASE" env-default:"go_forex_rates"`
	} `yaml:"l2_cache"`

	// Providers settings
	Providers map[string]ProviderConfig
}

ApplicationConfig represents structure of main application config

type EngineConfig

type EngineConfig struct {
	// Running mode: debug / release
	Mode string `yaml:"mode" env:"mode" env-default:"debug"`

	// Listen port
	Port int `yaml:"port" env:"PORT" env-default:9090`
}

EngineConfig is HTTP server settings

type FailedApiResponse

type FailedApiResponse struct {
	// Success Returns true or false depending on whether or not your API request has succeeded.
	Success bool `json:"success"`

	// Code and error message
	Error ApiError `json:"error"`
}

FailedApiResponse response, when error occurred

func NewFailedApiResponse

func NewFailedApiResponse(code int, info string) *FailedApiResponse

NewFailedApiResponse constructor

func (*FailedApiResponse) GetError

func (a *FailedApiResponse) GetError() ApiError

GetError returns Error value

func (*FailedApiResponse) GetSuccess

func (a *FailedApiResponse) GetSuccess() bool

GetSuccess returns Success value

func (*FailedApiResponse) SetError

SetError sets Error value

func (*FailedApiResponse) SetSuccess

func (a *FailedApiResponse) SetSuccess(success bool) *FailedApiResponse

SetSuccess sets Success value

type PingApiResponse

type PingApiResponse struct {
	// Message is service response as string
	Message string
}

PingApiResponse using for service health check

type ProviderConfig

type ProviderConfig struct {
	// Time location of provider's rates generating center
	Location string `yaml:"location" env-default:""UTC`

	// Time, when provider generate historical rates for today
	RatesGeneratedTime string `yaml:"rates_generated_time" env-default:"23:59:59"`

	// Access token for provider's API
	APIKey string `yaml:"api_key" env-default:""`

	// List of currencies, supporting by provider
	SupportedCurrencies []string `yaml:"supported_currencies"`

	// Enable or disable preload historical rates to L2 cache (database)
	HistoricalPreload bool `yaml:"historical_preload"`

	// Start date for preload historical currency rates
	HistoricalStartDate string `yaml:"historical_start_date"`
}

ProviderConfig is configuration of currency rates provider

type RatesRequest

type RatesRequest struct {
	// Requested endpoint
	Endpoint string `json:"endpoint"`

	// Requested provider code
	ProviderCode string `json:"provider_code"`

	// ProviderLocation name by code and provider config
	ProviderLocationName string `json:"provider_location_name"`

	// Requested currency rates date
	Date time.Time `json:"date"`

	// Requested base currency
	BaseCurrency string `json:"base_currency"`

	// Requested quoted currencies
	Symbols []string `json:"symbols"`

	// If true - do not use any type of cache, makes provider API request this case
	Force bool

	// Is this request build from another
	IsForwarded bool
}

RatesRequest is request to internal storage subsystem (multi-level cache)

func (*RatesRequest) FromGinContext

func (r *RatesRequest) FromGinContext(c *gin.Context, config *ApplicationConfig, endpoint string) error

FromGinContext fills with data from HTTP Request

func (*RatesRequest) FromString

func (r *RatesRequest) FromString(str string) error

FromString fills receiver with actual values from json string in arguments

func (*RatesRequest) IsEqualCurrencyRequest

func (r *RatesRequest) IsEqualCurrencyRequest() bool

IsEqualCurrencyRequest detects such type of request

func (*RatesRequest) String

func (r *RatesRequest) String() (string, error)

String returns string representation of JSON of this key structure

type RatesResponse

type RatesResponse struct {
	// Rates exchange rate data for the currencies you have requested.
	Rates map[string]float64 `json:"rates"`

	// Timestamp when provider generate rates in Rates if it single-pair, or first pair if multiple symbols in Rates
	Timestamp int64 `json:"timestamp"`
}

RatesResponse represents result for RatesRequest

func (*RatesResponse) FromString

func (r *RatesResponse) FromString(str string) error

FromString fills receiver with actual values from json string in arguments

func (*RatesResponse) String

func (r *RatesResponse) String() (string, error)

String returns string representation of JSON of this key structure

type SuccessApiResponse

type SuccessApiResponse struct {
	// Success true or false depending on whether or not your API request has succeeded.
	Success bool `json:"success"`

	// Historical true if a request for historical exchange rates was made.
	Historical bool `json:"historical"`

	// Date date for which historical rates were requested.
	Date string `json:"date"`

	// Timestamp the exact date and time (UNIX time stamp) the given rates were collected.
	Timestamp int64 `json:"timestamp"`

	// Base the three-letter currency code of the base currency used for this request.
	Base string `json:"base"`

	// Rates exchange rate data for the currencies you have requested.
	Rates map[string]float64 `json:"rates"`
}

SuccessApiResponse represents success API response

func NewSuccessApiResponse

func NewSuccessApiResponse(serviceRequest RatesRequest, serviceResponse RatesResponse) *SuccessApiResponse

NewSuccessApiResponse constructor

func NewSuccessApiResponseCurrencyEquals

func NewSuccessApiResponseCurrencyEquals(serviceRequest RatesRequest) *SuccessApiResponse

NewSuccessApiResponseCurrencyEquals returns response if base currency = quoted currency

Jump to

Keyboard shortcuts

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