chore: init repository
This commit is contained in:
51
handler/handler.go
Executable file
51
handler/handler.go
Executable file
@@ -0,0 +1,51 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"john/internal/storage/validators"
|
||||
"john/internal/utils"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"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 {
|
||||
va.RegisterValidationCtx(k, v.Validator)
|
||||
}
|
||||
}
|
||||
|
||||
return va
|
||||
}
|
||||
|
||||
func (hc *Context) GetHealth(c *gin.Context) {
|
||||
utils.JSON(c.Writer, http.StatusNoContent, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user