diff --git a/config.go b/config.go index 020ab1e5869d64280a469bb1a94a593e27087e94..3149d20a8d4aec6514d47b3dccf2314a7c241b1a 100644 --- a/config.go +++ b/config.go @@ -16,8 +16,8 @@ type EndpointConfig struct { } type CacheConfig struct { - Redis RedisCacheConfig `yaml:"redis"` - Memory MemoryCacheConfig `yaml:"memory"` + Redis *RedisCacheConfig `yaml:"redis"` + Memory *MemoryCacheConfig `yaml:"memory"` } type RedisCacheConfig struct { diff --git a/main.go b/main.go index ddffa64ba9ff90da442848927ee29212fa5b5c97..9c9e2ac04808c2bbe60b304bb22d02b47a894867 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,18 @@ func main() { autocompleteStations := loadAutocompleteStations() + var caches []bahn.CacheBackend + if config.Caches.Memory != nil { + caches = append(caches, NewMemoryCache(config.Caches.Memory.Timeout)) + } + if config.Caches.Redis != nil { + caches = append(caches, NewRedisCache( + config.Caches.Redis.Address, + config.Caches.Redis.Password, + config.Caches.Redis.Timeout, + )) + } + apiClient := bahn.ApiClient{ IrisBaseUrl: config.Endpoints.Iris, CoachSequenceBaseUrl: config.Endpoints.CoachSequence, @@ -63,14 +75,7 @@ func main() { HttpClient: &http.Client{ Timeout: config.RequestTimeout, }, - Caches: []bahn.CacheBackend{ - NewMemoryCache(config.Caches.Memory.Timeout), - NewRedisCache( - config.Caches.Redis.Address, - config.Caches.Redis.Password, - config.Caches.Redis.Timeout, - ), - }, + Caches: caches, } http.HandleFunc("/autocomplete/", func(w http.ResponseWriter, r *http.Request) {