diff --git a/internal/config/builder.go b/internal/config/builder.go index 3941012..6429f24 100644 --- a/internal/config/builder.go +++ b/internal/config/builder.go @@ -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", diff --git a/internal/config/builder_test.go b/internal/config/builder_test.go index 8a02880..234776a 100644 --- a/internal/config/builder_test.go +++ b/internal/config/builder_test.go @@ -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, }, diff --git a/internal/config/cli.go b/internal/config/cli.go index b7c90ce..de35a92 100644 --- a/internal/config/cli.go +++ b/internal/config/cli.go @@ -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, "") diff --git a/internal/config/config.go b/internal/config/config.go index 6f60465..e1d815e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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"`