add validation

This commit is contained in:
kandrusyak
2023-08-02 15:57:56 +03:00
parent 481bd0b788
commit a1705758df
3 changed files with 18 additions and 9 deletions

View File

@@ -12,6 +12,8 @@ import (
"gorm.io/gorm/logger"
"log"
"os"
"reflect"
"strings"
"time"
)
@@ -40,6 +42,13 @@ func main() {
db.AutoMigrate(&model.Event{})
validate := validator.New()
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})
var h = &handler.Handler{DB: db, Validator: validate}