diff --git a/main.go b/main.go index 5d3a8d6..e7ac802 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "strings" + "time" ) type funcType func() map[string]string @@ -28,16 +29,16 @@ func main() { func handler(m *mux.Router) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + driver := strings.ReplaceAll(r.URL.Path, "/", "") + service := r.URL.Query().Get("service") + incompatibleError := fmt.Sprintf("%s is not a compatible driver with service: %s", driver, service) defer func() { - driver := strings.ReplaceAll(r.URL.Path, "/", "") - service := r.URL.Query().Get("service") - incompatibleError := fmt.Sprintf("%s is not a compatible driver with service: %s", driver, service) if err := recover(); err != nil { http.Error(w, incompatibleError, http.StatusInternalServerError) } }() - handler := http.Handler(m) - handler.ServeHTTP(w, r) + timeoutHandler := http.TimeoutHandler(m, 3*time.Second, incompatibleError) + timeoutHandler.ServeHTTP(w, r) } } diff --git a/redis.go b/redis.go index 9f128dc..4da3f9b 100644 --- a/redis.go +++ b/redis.go @@ -19,6 +19,7 @@ func redisHandler(w http.ResponseWriter, r *http.Request) { service := r.URL.Query().Get("service") redisRoute := strings.ReplaceAll(service, "/", "") redisConnectionStr := fmt.Sprintf("%s:6379", redisRoute) + log.Print(fmt.Sprintf("Using %s as the connstring", redisConnectionStr)) fmt.Fprintf(w, redisConnector(redisConnectionStr, redisRoute)) } @@ -36,6 +37,10 @@ func redisConnector(connectionString string, version string) string { DB: 0, }) + if err := client.Ping(ctx).Err(); err != nil { + panic(err) + } + for _, e := range os.Environ() { pair := strings.SplitN(e, "=", 2) err := client.Set(ctx, pair[0], pair[1], 0).Err()