Files
budget-backend/handler/handler.go
kratisto f8df24c29d
Some checks failed
golangci-lint / lint (push) Failing after 1m30s
Test / test (push) Failing after 2m17s
chore: migrate to gitea
2026-01-27 01:45:58 +01:00

56 lines
1.1 KiB
Go
Executable File

package handler
import (
"net/http"
"reflect"
"strings"
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/validators"
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/utils"
"github.com/gin-gonic/gin"
"gopkg.in/go-playground/validator.v9"
)
type Config struct {
Mock bool
DBConnectionURI string
Port int
LogLevel string
LogFormat string
}
type Context struct {
Validator *validator.Validate
}
func NewContext() *Context {
return &Context{Validator: newValidator()}
}
func newValidator() *validator.Validate {
va := validator.New()
va.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)
if len(name) < 1 {
return ""
}
return name[0]
})
for k, v := range validators.CustomValidators {
if v.Validator != nil {
err := va.RegisterValidationCtx(k, v.Validator)
if err != nil {
return nil
}
}
}
return va
}
func (hc *Context) GetHealth(c *gin.Context) {
utils.JSON(c.Writer, http.StatusNoContent, nil)
}