Skip to content

Commit

Permalink
Add health check
Browse files Browse the repository at this point in the history
  • Loading branch information
adeveloper-wq committed Jun 18, 2024
1 parent 6e033cf commit 39ae948
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM golang
COPY main.go /go/src/main.go
RUN go build -o /go/bin/main /go/src/main.go
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl -f http://localhost:8000/health || exit 1
CMD ["/go/bin/main"]
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ func checkAndProxy(w http.ResponseWriter, r *http.Request) {
log.Printf("Request: %s %s\n", r.Method, r.URL.Path)
}

// Health check endpoint
if r.URL.Path == "/health" {
w.WriteHeader(http.StatusOK)
return
}

if !checkRequest(w, r) {
http.Error(w, "Invalid", http.StatusBadRequest)
return
Expand Down

0 comments on commit 39ae948

Please sign in to comment.