Documentation
¶
Index ¶
- Constants
- Variables
- func DoRequest(client HTTPClient, url string, headers map[string]string, timeoutSecond int) ([]byte, int, error)
- func GetChainID(chainNameOrID string) (string, error)
- func GetChainName(chainID string) (string, error)
- func GetIntPtr(value interface{}) *int
- func GetStringPtr(value interface{}) *string
- func HandleErrorWithThrottling(redisClient *RedisClient, logger zerolog.Logger, key string, errorMsg string)
- func LoadAllowApiKey()
- func LoadAllowedTokens()
- func LoadDodoexRouteUrl()
- func LoadEnv() (struct{}, error)
- func LoadRefuseChainId()
- func LoadUSDTAddresses()
- func NewEtcdClient() *clientv3.Client
- func NewKoanfInstance() *koanf.Koanf
- func NewLogger(cfg *koanf.Koanf) zerolog.Logger
- func ParseJSONResponse(body []byte, result interface{}) error
- func SendSlackAlert(alertedKey string, message string, logger zerolog.Logger, ...) error
- func SetupCfg() *koanf.Koanf
- func SetupRealDB() *database.Database
- func UpdateChainMapping()
- type Amqp
- type CoinChecker
- type CoinsThrottler
- type HTTPClient
- type PreforkHook
- type RedisClient
- func (r *RedisClient) AcquireLock(lockKey string, ttl time.Duration) bool
- func (r *RedisClient) Close() error
- func (r *RedisClient) Connect()
- func (r *RedisClient) DeleteCoinBatch(keys []string)
- func (r *RedisClient) DeleteKeyBatch(keys []string) error
- func (r *RedisClient) DeleteKeysByPrefix(prefix string) error
- func (r *RedisClient) GetCurrentPriceCache(coinID string) (string, error)
- func (r *RedisClient) GetCurrentPricesCache(coinIDs []string) (map[string]string, error)
- func (r *RedisClient) GetHistoricalPriceCache(coinID string, dayDate string) (string, error)
- func (r *RedisClient) HasHistoricalPriceCache(coinID string) (bool, error)
- func (r *RedisClient) ReleaseLock(lockKey string)
- func (r *RedisClient) SetCurrentPriceCache(coinID string, price string) error
- func (r *RedisClient) SetHistoricalPriceCache(coinID string, dayDate string, price string) error
- type SlackPayload
- type USDTAddress
Constants ¶
View Source
const ( // CoinsThrottlePrefix 节流键的前缀 CoinsThrottlePrefix = "coins_throttle:" // CoinsThrottleCountPrefix 节流计数键的前缀 CoinsThrottleCountPrefix = "coins_throttle_count:" // CoinsThrottleDuration 节流键的有效期 CoinsThrottleDuration = 60 * 1 * time.Second // CoinsThrottleCountResetDuration 节流计数键的重置时间 CoinsThrottleCountResetDuration = 30 * time.Minute // CoinsMaxThrottleCount 最大节流计数 CoinsMaxThrottleCount = 3 // SlackNotificationResetDuration Slack 通知重置时间 CoinsSlackNotificationResetDuration = 30 * time.Minute )
Throttler 配置常量
View Source
const ( RedisErrorCountPrefix = "error_count:" RedisErrorCountDuration = 10 * time.Minute // 计数过期时间 RedisErrorThreshold = 5 // 阈值 SlackWebhookURL = "https://hooks.slack.com/services/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" SlackNotificationResetDuration = 60 * 24 * time.Minute // 通知重置时间 )
常量配置
Variables ¶
View Source
var ( DodoexRouteUrl = "https://api.dodoex.io/route-service/v2/backend/swap" AllowApiKeyNil = true AllowApiKeyNilRateLimiter = 1000 AllowedTokens = []string{"*USD*", "DAI", "*DODO", "JOJO", "*BTC*", "*ETH*", "*MATIC*", "*BNB*", "*AVAX", "*NEAR", "*XRP", "TON*", "*ARB", "ENS"} // 设置默认值 //拒绝的链ID RefuseChainIdMap = map[string]int{ "128": 1, } )
Functions ¶
func GetChainID ¶
GetChainID 根据链名称或链ID字符串返回相应的链ID
func GetStringPtr ¶
func GetStringPtr(value interface{}) *string
func HandleErrorWithThrottling ¶
func HandleErrorWithThrottling(redisClient *RedisClient, logger zerolog.Logger, key string, errorMsg string)
HandleErrorWithThrottling 处理错误统计和节流
func LoadAllowApiKey ¶
func LoadAllowApiKey()
func LoadDodoexRouteUrl ¶
func LoadDodoexRouteUrl()
func LoadRefuseChainId ¶
func LoadRefuseChainId()
func NewEtcdClient ¶
func NewKoanfInstance ¶
func NewKoanfInstance() *koanf.Koanf
func ParseJSONResponse ¶
ParseJSONResponse parses the JSON response into the given result structure.
func SendSlackAlert ¶
func SetupRealDB ¶
Types ¶
type Amqp ¶
type CoinChecker ¶
type CoinsThrottler ¶
type CoinsThrottler struct {
// contains filtered or unexported fields
}
CoinsThrottler 结构体,用于持有 Redis 客户端和其他配置
func NewCoinsThrottler ¶
func NewCoinsThrottler(redisClient *RedisClient, logger zerolog.Logger, coinChecker CoinChecker) *CoinsThrottler
NewCoinsThrottler 创建一个新的 CoinsThrottler 实例
func (*CoinsThrottler) CoinsThrottle ¶
func (t *CoinsThrottler) CoinsThrottle(coinsId string, reqeusetStatus string) bool
CoinsThrottle 增加节流计数并检查是否超过限制和允许发送Slack,如果超过限制则返回 true 并且重置
func (*CoinsThrottler) GetAlertedKey ¶
func (t *CoinsThrottler) GetAlertedKey(coinsId string) string
func (*CoinsThrottler) IsCoinsThrottled ¶
func (t *CoinsThrottler) IsCoinsThrottled(coinsId string) bool
IsCoinsThrottled 检查请求是否被节流
type RedisClient ¶
type RedisClient struct { Client *redis.Client // contains filtered or unexported fields }
func NewRedisClient ¶
func NewRedisClient(cfg *koanf.Koanf, logger zerolog.Logger) *RedisClient
func SetupRealRedis ¶
func SetupRealRedis() *RedisClient
func (*RedisClient) AcquireLock ¶
func (r *RedisClient) AcquireLock(lockKey string, ttl time.Duration) bool
func (*RedisClient) Close ¶
func (r *RedisClient) Close() error
func (*RedisClient) Connect ¶
func (r *RedisClient) Connect()
func (*RedisClient) DeleteCoinBatch ¶
func (r *RedisClient) DeleteCoinBatch(keys []string)
func (*RedisClient) DeleteKeyBatch ¶
func (r *RedisClient) DeleteKeyBatch(keys []string) error
func (*RedisClient) DeleteKeysByPrefix ¶
func (r *RedisClient) DeleteKeysByPrefix(prefix string) error
func (*RedisClient) GetCurrentPriceCache ¶
func (r *RedisClient) GetCurrentPriceCache(coinID string) (string, error)
func (*RedisClient) GetCurrentPricesCache ¶
func (r *RedisClient) GetCurrentPricesCache(coinIDs []string) (map[string]string, error)
func (*RedisClient) GetHistoricalPriceCache ¶
func (r *RedisClient) GetHistoricalPriceCache(coinID string, dayDate string) (string, error)
func (*RedisClient) HasHistoricalPriceCache ¶
func (r *RedisClient) HasHistoricalPriceCache(coinID string) (bool, error)
func (*RedisClient) ReleaseLock ¶
func (r *RedisClient) ReleaseLock(lockKey string)
func (*RedisClient) SetCurrentPriceCache ¶
func (r *RedisClient) SetCurrentPriceCache(coinID string, price string) error
func (*RedisClient) SetHistoricalPriceCache ¶
func (r *RedisClient) SetHistoricalPriceCache(coinID string, dayDate string, price string) error
type SlackPayload ¶
type USDTAddress ¶
USDTAddress 存储 USDT 地址及其小数位数
func GetUSDTAddress ¶
func GetUSDTAddress(chainID string) (USDTAddress, error)
GetUSDTAddress 根据链ID返回相应的USDT地址及其小数位数
Click to show internal directories.
Click to hide internal directories.