mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +02:00
config/config.go: Use redis and telegram config from app/serivce packages.
This commit is contained in:
parent
a2ab62afa0
commit
764db98417
2 changed files with 12 additions and 31 deletions
|
|
@ -3,36 +3,25 @@ package config
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"eosio-ship-trace-reader/app/service/redis"
|
||||||
|
"eosio-ship-trace-reader/app/service/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
|
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 {
|
type Config struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ShipApi string `json:"ship_api"`
|
ShipApi string `json:"ship_api"`
|
||||||
Api string `json:"api"`
|
Api string `json:"api"`
|
||||||
|
|
||||||
Redis RedisConfig `json:"redis"`
|
|
||||||
|
|
||||||
Telegram TelegramConfig `json:"telegram"`
|
|
||||||
|
|
||||||
IrreversibleOnly bool `json:"irreversible_only"`
|
IrreversibleOnly bool `json:"irreversible_only"`
|
||||||
MaxMessagesInFlight uint32 `json:"max_messages_in_flight"`
|
MaxMessagesInFlight uint32 `json:"max_messages_in_flight"`
|
||||||
StartBlockNum uint32 `json:"start_block_num"`
|
StartBlockNum uint32 `json:"start_block_num"`
|
||||||
EndBlockNum uint32 `json:"end_block_num"`
|
EndBlockNum uint32 `json:"end_block_num"`
|
||||||
|
|
||||||
|
Redis redis.Config `json:"redis"`
|
||||||
|
Telegram telegram.Config `json:"telegram"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(data []byte) (*Config, error) {
|
func Parse(data []byte) (*Config, error) {
|
||||||
|
|
@ -41,12 +30,7 @@ func Parse(data []byte) (*Config, error) {
|
||||||
EndBlockNum: NULL_BLOCK_NUMBER,
|
EndBlockNum: NULL_BLOCK_NUMBER,
|
||||||
MaxMessagesInFlight: 10,
|
MaxMessagesInFlight: 10,
|
||||||
IrreversibleOnly: false,
|
IrreversibleOnly: false,
|
||||||
Redis: RedisConfig{
|
Redis: redis.DefaultConfig,
|
||||||
Addr: "localhost:6379",
|
|
||||||
Password: "",
|
|
||||||
DB: 0,
|
|
||||||
Prefix: "ship",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := json.Unmarshal(data, &cfg)
|
err := json.Unmarshal(data, &cfg)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package config
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"eosio-ship-trace-reader/app/service/redis"
|
||||||
|
"eosio-ship-trace-reader/app/service/telegram"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -12,12 +14,7 @@ func TestParse_Default(t *testing.T) {
|
||||||
EndBlockNum: NULL_BLOCK_NUMBER,
|
EndBlockNum: NULL_BLOCK_NUMBER,
|
||||||
MaxMessagesInFlight: 10,
|
MaxMessagesInFlight: 10,
|
||||||
IrreversibleOnly: false,
|
IrreversibleOnly: false,
|
||||||
Redis: RedisConfig{
|
Redis: redis.DefaultConfig,
|
||||||
Addr: "localhost:6379",
|
|
||||||
Password: "",
|
|
||||||
DB: 0,
|
|
||||||
Prefix: "ship",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := Parse([]byte(`{}`))
|
cfg, err := Parse([]byte(`{}`))
|
||||||
|
|
@ -34,11 +31,11 @@ func TestParse(t *testing.T) {
|
||||||
EndBlockNum: 23872222,
|
EndBlockNum: 23872222,
|
||||||
IrreversibleOnly: true,
|
IrreversibleOnly: true,
|
||||||
MaxMessagesInFlight: 1337,
|
MaxMessagesInFlight: 1337,
|
||||||
Telegram: TelegramConfig{
|
Telegram: telegram.Config{
|
||||||
Id: "110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw",
|
Id: "110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw",
|
||||||
Channel: -123456789,
|
Channel: -123456789,
|
||||||
},
|
},
|
||||||
Redis: RedisConfig{
|
Redis: redis.Config{
|
||||||
Addr: "localhost:6379",
|
Addr: "localhost:6379",
|
||||||
Password: "passwd",
|
Password: "passwd",
|
||||||
DB: 4,
|
DB: 4,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue