-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (39 loc) · 990 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"errors"
"fmt"
"github.com/debug-ing/validation-go/pkg/validation"
)
type UpdateIAMUserRequest struct {
ID string `validate:"required,uuid"`
Name string `validate:"required,minlength=10"`
LName string `validate:"required,minlength=10"`
Age int `validate:"required,numeric,minmax=18-100"`
Nike string `validate:"required,between=1-10"`
Test string `validate:"contains=hello"`
}
func main() {
req := UpdateIAMUserRequest{
ID: "d89cb260-36ff-4206-8979-6c1ce693ab28",
Name: "ddsffddddd",
LName: "ddsffddddd",
Age: 29,
Nike: "sdfkjdf",
Test: "hell1o",
}
validation.AddCustomValidator("test", "%s vard kon", validateRequired)
err := validation.ValidateStruct(req)
if err != nil {
fmt.Println("Validation error:", err)
} else {
fmt.Println("Validation passed")
}
//
}
func validateRequired(value string, errorMsg string) error {
if value == "" {
fmt.Println(errorMsg)
return errors.New(errorMsg)
}
return nil
}