http: fix cache configuration marshal/unmarshal

Also, enable Redis by default, as stated in changelog.
This commit is contained in:
Vincent Bernat
2022-12-22 18:22:53 +01:00
parent 07a7524f8d
commit 4db5ac7544
3 changed files with 15 additions and 1 deletions

View File

@@ -102,6 +102,10 @@ inlet:
- ClassifyInternal()
console:
http:
cache:
type: redis
server: redis:6379
database:
saved-filters:
# These are prepopulated filters you can select in a drop-down

View File

@@ -144,7 +144,7 @@ func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConf
// Alter config with a copy of the concrete type
defaultV := innerConfiguration()
original := reflect.Indirect(reflect.ValueOf(defaultV))
if !configField.IsNil() && configField.Elem().Type().Elem() == reflect.TypeOf(defaultV).Elem() {
if !configField.IsNil() && configField.Elem().Type() == reflect.TypeOf(defaultV) {
// Use the value we already have instead of default.
original = reflect.Indirect(configField.Elem())
}

View File

@@ -100,6 +100,16 @@ func DefaultConfiguration() Configuration {
}
}
// MarshalYAML undoes ConfigurationUnmarshallerHook().
func (cc CacheConfiguration) MarshalYAML() (interface{}, error) {
return helpers.ParametrizedConfigurationMarshalYAML(cc, cacheConfigurationMap)
}
// MarshalJSON undoes ConfigurationUnmarshallerHook().
func (cc CacheConfiguration) MarshalJSON() ([]byte, error) {
return helpers.ParametrizedConfigurationMarshalJSON(cc, cacheConfigurationMap)
}
var cacheConfigurationMap = map[string](func() CacheBackendConfiguration){
"memory": DefaultMemoryCacheConfiguration,
"redis": DefaultRedisCacheConfiguration,