mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 10:55:51 +02:00
bug fix
This commit is contained in:
parent
ad421905a8
commit
dd6e19657a
162 changed files with 15071 additions and 932 deletions
|
@ -1,14 +1,46 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
val "github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func ErrorHandler(c *gin.Context, err error) {
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
type ValidError struct {
|
||||
Key string
|
||||
Message string
|
||||
}
|
||||
|
||||
type ValidErrors gin.H
|
||||
|
||||
func BindAndValid(c *gin.Context, v interface{}) (bool, ValidErrors) {
|
||||
errs := make(ValidErrors)
|
||||
err := c.ShouldBind(v)
|
||||
if err != nil {
|
||||
|
||||
v := c.Value("trans")
|
||||
trans, _ := v.(ut.Translator)
|
||||
verrs, ok := err.(val.ValidationErrors)
|
||||
if !ok {
|
||||
return false, errs
|
||||
}
|
||||
|
||||
for key, value := range verrs.Translate(trans) {
|
||||
errs[key] = value
|
||||
}
|
||||
|
||||
return false, errs
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue