1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-16 04:24:56 +02:00

config/config.go: Use redis and telegram config from app/serivce packages.

This commit is contained in:
Henrik Hautakoski 2023-03-08 14:04:20 +01:00
parent a2ab62afa0
commit 764db98417
2 changed files with 12 additions and 31 deletions

View file

@ -3,36 +3,25 @@ package config
import (
"encoding/json"
"io/ioutil"
"eosio-ship-trace-reader/app/service/redis"
"eosio-ship-trace-reader/app/service/telegram"
)
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
type RedisConfig struct {
Addr string `json:"addr"`
Password string `json:"password"`
DB int `json:"db"`
CacheID string `json:"cache_id"`
Prefix string `json:"prefix"`
}
type TelegramConfig struct {
Id string `json:"id"`
Channel int64 `json:"channel"`
}
type Config struct {
Name string `json:"name"`
ShipApi string `json:"ship_api"`
Api string `json:"api"`
Redis RedisConfig `json:"redis"`
Telegram TelegramConfig `json:"telegram"`
IrreversibleOnly bool `json:"irreversible_only"`
MaxMessagesInFlight uint32 `json:"max_messages_in_flight"`
StartBlockNum uint32 `json:"start_block_num"`
EndBlockNum uint32 `json:"end_block_num"`
Redis redis.Config `json:"redis"`
Telegram telegram.Config `json:"telegram"`
}
func Parse(data []byte) (*Config, error) {
@ -41,12 +30,7 @@ func Parse(data []byte) (*Config, error) {
EndBlockNum: NULL_BLOCK_NUMBER,
MaxMessagesInFlight: 10,
IrreversibleOnly: false,
Redis: RedisConfig{
Addr: "localhost:6379",
Password: "",
DB: 0,
Prefix: "ship",
},
Redis: redis.DefaultConfig,
}
err := json.Unmarshal(data, &cfg)

View file

@ -3,6 +3,8 @@ package config
import (
"testing"
"eosio-ship-trace-reader/app/service/redis"
"eosio-ship-trace-reader/app/service/telegram"
"github.com/stretchr/testify/require"
)
@ -12,12 +14,7 @@ func TestParse_Default(t *testing.T) {
EndBlockNum: NULL_BLOCK_NUMBER,
MaxMessagesInFlight: 10,
IrreversibleOnly: false,
Redis: RedisConfig{
Addr: "localhost:6379",
Password: "",
DB: 0,
Prefix: "ship",
},
Redis: redis.DefaultConfig,
}
cfg, err := Parse([]byte(`{}`))
@ -34,11 +31,11 @@ func TestParse(t *testing.T) {
EndBlockNum: 23872222,
IrreversibleOnly: true,
MaxMessagesInFlight: 1337,
Telegram: TelegramConfig{
Telegram: telegram.Config{
Id: "110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw",
Channel: -123456789,
},
Redis: RedisConfig{
Redis: redis.Config{
Addr: "localhost:6379",
Password: "passwd",
DB: 4,