Skip to content

Commit

Permalink
feat: add healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbu committed Sep 2, 2024
1 parent 32f39b5 commit 0ca8944
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@
name = "image-root";
paths = [packages.app];
};
config.Cmd = ["app"];
config = let
healthcheck = pkgs.writeShellApplication {
name = "healthcheck";
runtimeInputs = [pkgs.curl];
text = ''
test "$(curl --fail localhost:8080/health)" = "OK"
'';
};
in {
Healthcheck.Test = ["CMD" "${pkgs.lib.getExe healthcheck}"];
Entrypoint = ["app"];
};
};
};

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"app/pkg/app"
"app/pkg/routes/blog"
"app/pkg/routes/contact"
"app/pkg/routes/health"
"app/pkg/routes/resume"
"app/pkg/routes/root"
)
Expand All @@ -12,6 +13,7 @@ func main() {
serv := app.Server{Port: 8080}

serv.AddRoute("GET /", root.Handler)
serv.AddRoute("GET /health", health.Handler)
serv.AddRoute("GET /blog/{article...}", blog.Handler)
serv.AddRoute("GET /contact", contact.Handler)
serv.AddRoute("GET /resume", resume.Handler)
Expand Down
15 changes: 15 additions & 0 deletions pkg/routes/health/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package health

import (
"io"
"net/http"

"app/pkg/app"

"github.com/a-h/templ"
)

func Handler(serv *app.Server, w http.ResponseWriter, r *http.Request) (templ.Component, error) {
io.WriteString(w, "OK")
return nil, nil
}

0 comments on commit 0ca8944

Please sign in to comment.