add core/error/util files

This commit is contained in:
MaysWind
2020-10-17 17:22:10 +08:00
parent e5953c9f17
commit 6ad0a02d44
25 changed files with 917 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
package validators
import (
"github.com/go-playground/validator/v10"
"github.com/mayswind/lab/pkg/utils"
)
func ValidEmail(fl validator.FieldLevel) bool {
if value, ok := fl.Field().Interface().(string); ok {
if utils.IsValidEmail(value) {
return true
}
}
return false
}
+17
View File
@@ -0,0 +1,17 @@
package validators
import (
"strings"
"github.com/go-playground/validator/v10"
)
func NotBlank(fl validator.FieldLevel) bool {
if value, ok := fl.Field().Interface().(string); ok {
if value != "" && strings.Trim(value, " ") != "" {
return true
}
}
return false
}
+17
View File
@@ -0,0 +1,17 @@
package validators
import (
"github.com/go-playground/validator/v10"
"github.com/mayswind/lab/pkg/utils"
)
func ValidUsername(fl validator.FieldLevel) bool {
if value, ok := fl.Field().Interface().(string); ok {
if utils.IsValidUsername(value) {
return true
}
}
return false
}