Skip to content

Commit

Permalink
feat(api): added health checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed Apr 13, 2024
1 parent dc13d38 commit 52fbf71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions web/internal/handler/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package handler

import (
"github.com/labstack/echo/v4"
"net/http"
"time"
)

type healthCheck struct {
status string `json:"status"`
timestamp time.Time `json:"timestamp"`
}

func HealthChecker(c echo.Context) error {
status := healthCheck{
status: "ok",
timestamp: time.Now(),
}

return c.JSON(http.StatusOK, status)
}
6 changes: 5 additions & 1 deletion web/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package web

import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/wittano/komputer/web/internal/handler"
Expand All @@ -16,13 +17,16 @@ func NewWebConsoleServer(configPath string) (*echo.Echo, error) {

e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.BodyLimit(fmt.Sprintf("%dM", settings.Config.Upload.MaxFileSize)))

e.POST("/api/v1/audio", handler.UploadNewAudio)
e.GET("/api/v1/audio/:id", handler.GetAudio)
e.POST("/api/v1/audio", handler.UploadNewAudio)
e.DELETE("/api/v1/audio/:id", handler.RemoveAudio)

e.GET("/api/v1/setting", handler.GetSettings)
e.PUT("/api/v1/setting", handler.UpdateSettings)

e.GET("/api/v1/health", handler.HealthChecker)

return e, nil
}

0 comments on commit 52fbf71

Please sign in to comment.