mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
internal/config: Adding cache configuration
This commit is contained in:
parent
d1d4bf58b1
commit
ebbaf6e2c1
4 changed files with 35 additions and 0 deletions
|
|
@ -40,6 +40,8 @@ func NewBuilder() *Builder {
|
|||
"telegram.id": "telegram-id",
|
||||
"telegram.channel": "telegram-channel",
|
||||
|
||||
"cache.storage": "cache",
|
||||
|
||||
// AbiCache
|
||||
"abi_cache.api_timeout": "abi-cache-api-timeout",
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
shipclient "github.com/eosswedenorg-go/antelope-ship-client"
|
||||
"github.com/eosswedenorg/thalos/internal/log"
|
||||
"github.com/eosswedenorg/thalos/internal/types"
|
||||
"github.com/karlseguin/typed"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -23,6 +24,14 @@ func TestBuilder(t *testing.T) {
|
|||
MaxTime: 30 * time.Minute,
|
||||
FileTimestampFormat: "20060102@150405",
|
||||
},
|
||||
Cache: Cache{
|
||||
Storage: "memcached",
|
||||
Options: typed.Typed{
|
||||
"ttl": "300m",
|
||||
"size": 400,
|
||||
"super_fast_mode": true,
|
||||
},
|
||||
},
|
||||
AbiCache: AbiCache{
|
||||
ApiTimeout: time.Minute * 300,
|
||||
},
|
||||
|
|
@ -56,6 +65,12 @@ func TestBuilder(t *testing.T) {
|
|||
name: "ship-reader-1"
|
||||
api: "http://127.0.0.1:8080"
|
||||
message_codec: "mojibake"
|
||||
cache:
|
||||
storage: memcached
|
||||
options:
|
||||
ttl: 300m
|
||||
size: 400
|
||||
super_fast_mode: true
|
||||
abi_cache:
|
||||
api_timeout: 300m
|
||||
log:
|
||||
|
|
@ -101,6 +116,9 @@ func TestBuilder_WithDefaultConfig(t *testing.T) {
|
|||
MaxTime: time.Hour * 24,
|
||||
FileTimestampFormat: "2006-01-02_150405",
|
||||
},
|
||||
Cache: Cache{
|
||||
Storage: "redis",
|
||||
},
|
||||
AbiCache: AbiCache{
|
||||
ApiTimeout: time.Second,
|
||||
},
|
||||
|
|
@ -141,6 +159,7 @@ func TestBuilder_Flags(t *testing.T) {
|
|||
require.NoError(t, flags.Set("redis-password", "secret123"))
|
||||
require.NoError(t, flags.Set("redis-db", "3"))
|
||||
require.NoError(t, flags.Set("redis-prefix", "custom-prefix"))
|
||||
require.NoError(t, flags.Set("cache", "memcached"))
|
||||
require.NoError(t, flags.Set("abi-cache-api-timeout", "16h"))
|
||||
require.NoError(t, flags.Set("telegram-id", "72983126312982618"))
|
||||
require.NoError(t, flags.Set("telegram-channel", "-293492332"))
|
||||
|
|
@ -169,6 +188,9 @@ func TestBuilder_Flags(t *testing.T) {
|
|||
MaxTime: time.Minute * 10,
|
||||
FileTimestampFormat: "0102-15:04:05",
|
||||
},
|
||||
Cache: Cache{
|
||||
Storage: "memcached",
|
||||
},
|
||||
AbiCache: AbiCache{
|
||||
ApiTimeout: time.Hour * 16,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ func GetFlags() *pflag.FlagSet {
|
|||
flags.String("telegram-id", "", "Id of telegram bot")
|
||||
flags.Int64("telegram-channel", 0, "Telegram channel to send notifications to")
|
||||
|
||||
// Cache
|
||||
flags.String("cache", "redis", "What cache driver to use")
|
||||
|
||||
// AbiCache
|
||||
flags.Duration("abi-cache-api-timeout", time.Second, "")
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/eosswedenorg/thalos/internal/log"
|
||||
"github.com/eosswedenorg/thalos/internal/types"
|
||||
"github.com/karlseguin/typed"
|
||||
)
|
||||
|
||||
type RedisConfig struct {
|
||||
|
|
@ -15,6 +16,11 @@ type RedisConfig struct {
|
|||
Prefix string `yaml:"prefix"`
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
Storage string `yaml:"storage" mapstructure:"storage"`
|
||||
Options typed.Typed `yaml:"options" mapstructure:"options"`
|
||||
}
|
||||
|
||||
type TelegramConfig struct {
|
||||
Id string `yaml:"id" mapstructure:"id"`
|
||||
Channel int64 `yaml:"channel" mapstructure:"channel"`
|
||||
|
|
@ -42,6 +48,8 @@ type Config struct {
|
|||
|
||||
Log log.Config `yaml:"log" mapstructure:"log"`
|
||||
|
||||
Cache Cache `yaml:"cache" mapstructure:"cache"`
|
||||
|
||||
Redis RedisConfig `yaml:"redis" mapstructure:"redis"`
|
||||
MessageCodec string `yaml:"message_codec" mapstructure:"message_codec"`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue