refactor: fix lint errors; improve error handling

This commit is contained in:
yusing
2026-02-22 16:04:25 +08:00
parent 3a7d1f8b18
commit 0f78158c64
40 changed files with 191 additions and 136 deletions

View File

@@ -41,20 +41,18 @@ func ValidateWithCustomValidator(v reflect.Value) error {
if elemType.Implements(validatorType) {
return v.Elem().Interface().(CustomValidator).Validate()
}
} else {
if vt.PkgPath() != "" { // not a builtin type
// prioritize pointer method
if v.CanAddr() {
vAddr := v.Addr()
if vAddr.Type().Implements(validatorType) {
return vAddr.Interface().(CustomValidator).Validate()
}
}
// fallback to value method
if vt.Implements(validatorType) {
return v.Interface().(CustomValidator).Validate()
} else if vt.PkgPath() != "" { // not a builtin type
// prioritize pointer method
if v.CanAddr() {
vAddr := v.Addr()
if vAddr.Type().Implements(validatorType) {
return vAddr.Interface().(CustomValidator).Validate()
}
}
// fallback to value method
if vt.Implements(validatorType) {
return v.Interface().(CustomValidator).Validate()
}
}
return nil
}