From 40a50fa493ab05f36200b2fc42e48f065ccb2e5b Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 8 Oct 2023 12:08:10 +0200 Subject: [PATCH] updated to validator to rsvalidator --- commit_and_tag.sh | 18 +++++++++++++++++ rsvalidator/rsvalidator.go | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 commit_and_tag.sh create mode 100644 rsvalidator/rsvalidator.go diff --git a/commit_and_tag.sh b/commit_and_tag.sh new file mode 100755 index 0000000..7dad5a7 --- /dev/null +++ b/commit_and_tag.sh @@ -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 \ No newline at end of file diff --git a/rsvalidator/rsvalidator.go b/rsvalidator/rsvalidator.go new file mode 100644 index 0000000..e23f518 --- /dev/null +++ b/rsvalidator/rsvalidator.go @@ -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") +}