updated to validator to rsvalidator

main v1.0.3
alex 2023-10-08 12:08:10 +02:00
parent 3e564521e2
commit 40a50fa493
2 changed files with 59 additions and 0 deletions

18
commit_and_tag.sh Executable file
View File

@ -0,0 +1,18 @@
git add *
read -p "Commit message: " commit_message
git commit -m "$commit_message"
current_tag=$(git describe --abbrev=0 --tags)
IFS='.' read -ra tag_parts <<< "$current_tag"
major="${tag_parts[0]}"
minor="${tag_parts[1]}"
patch="${tag_parts[2]}"
patch=$((patch + 1))
new_tag="$major.$minor.$patch"
git tag "$new_tag"
git push origin master
git push --tags

View File

@ -0,0 +1,41 @@
package rsvalidator
import (
"log"
"regexp"
"strings"
"github.com/go-playground/validator/v10"
)
type ErrorResponse struct {
FailedField string
Tag string
Value string
}
var Validate = validator.New()
func ValidateStruct(event interface{}) []*ErrorResponse {
var errors []*ErrorResponse
err := Validate.Struct(event)
if err != nil {
for _, err := range err.(validator.ValidationErrors) {
var element ErrorResponse
element.FailedField = err.StructNamespace()
element.Tag = err.Tag()
element.Value = err.Param()
errors = append(errors, &element)
}
}
return errors
}
func validateNumericString(fl validator.FieldLevel) bool {
str := fl.Field().String()
return strings.TrimSpace(str) != "" && regexp.MustCompile(`^[0-9]+$`).MatchString(str)
}
func test() {
log.Println("test")
}