add initial application structure with configuration, logging, and health check endpoints

This commit is contained in:
kever
2026-01-15 22:48:28 +08:00
parent fe67f09e72
commit 2efefc7e05
24 changed files with 178 additions and 83 deletions

View File

@@ -1,14 +1,16 @@
package exception
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
"epic-ent/internal/domain/vo"
)
func RegisterErrorHandler(e *echo.Echo) {
func RegisterErrorHandler(e *echo.Echo, logger *zap.Logger) {
e.HTTPErrorHandler = func(err error, c echo.Context) {
code := http.StatusInternalServerError
msg := err.Error()
@@ -19,6 +21,14 @@ func RegisterErrorHandler(e *echo.Echo) {
}
}
verbose := fmt.Sprintf("%+v", err)
logger.With(
zap.Int("status", code),
zap.String("path", c.Path()),
zap.String("method", c.Request().Method),
zap.Error(err),
).Error(verbose)
_ = c.JSON(code, vo.Error(msg))
}
}