Files
Go-Template/http_handlers/index/index.go
Ron Rise 12bbacced0
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m5s
lint (#2)
Reviewed-on: Siteworxpro/Go-Template#2
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
2025-06-18 02:16:10 +00:00

42 lines
1.0 KiB
Go

package index
import (
"gitea.siteworxpro.com/Siteworxpro/Go-Template/http_handlers/errors"
"gitea.siteworxpro.com/Siteworxpro/Go-Template/logger"
"github.com/labstack/echo/v4"
"net/http"
)
func Register(g *echo.Group) {
index := new(index)
g.GET("", index.Get)
g.POST("", index.Post)
g.PUT("", index.Put)
g.DELETE("", index.Delete)
g.PATCH("", index.Patch)
}
type index struct{}
func (i *index) Get(c echo.Context) error {
c.Get("logger").(logger.Interface).Info("Index handler called")
return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
}
func (i *index) Post(c echo.Context) error {
return errors.NewBadRequestError(c, map[string]string{"test": "Test is a required field"})
}
func (i *index) Put(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
}
func (i *index) Delete(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
}
func (i *index) Patch(c echo.Context) error {
return errors.NewNotFoundError(c)
}