Skip to content

Commit

Permalink
Reincorporates the timeouthandler into the updates handler
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed May 10, 2024
1 parent 423f5d7 commit 3f8b849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"strings"
"time"
)

type funcType func() map[string]string
Expand All @@ -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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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()
Expand Down

0 comments on commit 3f8b849

Please sign in to comment.