Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • justJanne/bahn-proxy
1 result
Select Git revision
  • master
1 result
Show changes
Commits on Source (2)
......@@ -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 {
......
......@@ -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) {
......@@ -278,6 +283,10 @@ func main() {
return
}
})
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, _ = w.Write([]byte("ok\n"))
})
if err := http.ListenAndServe(*listen, nil); err != nil {
log.Fatal(err)
}
......