Skip to content

Commit

Permalink
update healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
kiberdruzhinnik committed Mar 3, 2024
1 parent 0cdc15e commit 29147b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions cmd/healthcheck/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package main

import (
"encoding/json"
"io"
"log"
"net/http"
)

type HealthCheckJSON struct {
Status string `json:"status"`
}

func main() {
resp, err := http.Get("http://127.0.0.1:8080/healthcheck")

Expand All @@ -21,8 +26,13 @@ func main() {
log.Fatalln(err)
}

status := string(body)
if status != "ok" {
var healthcheck HealthCheckJSON
err = json.Unmarshal(body, &healthcheck)
if err != nil {
log.Fatalln(err)
}
if healthcheck.Status != "ok" {
log.Fatalln("status is not ok")
}
log.Println("status is ok")
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
depends_on:
- redis-cache
healthcheck:
test: [ "./healthcheck" ]
test: [ "CMD-SHELL", "./healthcheck" ]
interval: 30s
timeout: 10s
retries: 3
Expand Down

0 comments on commit 29147b3

Please sign in to comment.