aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/api/health.go29
-rw-r--r--internal/api/new.go9
2 files changed, 37 insertions, 1 deletions
diff --git a/internal/api/health.go b/internal/api/health.go
new file mode 100644
index 0000000..61d5185
--- /dev/null
+++ b/internal/api/health.go
@@ -0,0 +1,29 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type HealthResponse struct {
+ Status string `json:"status"`
+}
+
+func (s *Server) handleHealth(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+ w.Header().Set("Content-Type", "application/json")
+
+ response := HealthResponse{
+ Status: "ok",
+ }
+
+ if err := json.NewEncoder(w).Encode(response); err != nil {
+ http.Error(
+ w,
+ http.StatusText(http.StatusInternalServerError),
+ http.StatusInternalServerError,
+ )
+ }
+}
diff --git a/internal/api/new.go b/internal/api/new.go
index a9a08eb..d225b02 100644
--- a/internal/api/new.go
+++ b/internal/api/new.go
@@ -10,9 +10,16 @@ func New(config Config) *Server {
Handler: mux,
}
- return &Server{
+ srv := &Server{
config: config,
mux: mux,
http: server,
}
+
+ srv.mux.HandleFunc(
+ "GET /health",
+ srv.handleHealth,
+ )
+
+ return srv
}