enhance: show the form error details of Preference

This commit is contained in:
0xJacky 2024-01-28 15:01:46 +08:00
parent b0a3989ef4
commit 398eea2159
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
8 changed files with 74 additions and 22 deletions

View file

@ -38,18 +38,18 @@ func BindAndValid(c *gin.Context, target interface{}) bool {
return false
}
t := reflect.TypeOf(target)
t := reflect.TypeOf(target).Elem()
errorsMap := make(map[string]interface{})
for _, value := range verrs {
var path []string
namespace := strings.Split(value.StructNamespace(), ".")
if t.Name() == "" && len(namespace) > 1 {
logger.Debug(t.Name(), namespace)
if t.Name() != "" && len(namespace) > 1 {
namespace = namespace[1:]
}
getJsonPath(t.Elem(), namespace, &path)
getJsonPath(t, namespace, &path)
insertError(errorsMap, path, value.Tag())
}