Skip to content

Commit 03799a5

Browse files
committed
fix: Validate middleware function now dereferences the body parameter if it's a pointer
1 parent ecce3d5 commit 03799a5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

http/middleware/validator/middleware.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
goreflect "github.com/ralvarezdev/go-reflect"
77
govalidatorstructmapper "github.com/ralvarezdev/go-validator/struct/mapper"
88
"net/http"
9+
"reflect"
910
)
1011

1112
// Middleware struct
@@ -41,6 +42,11 @@ func (m *Middleware) Validate(
4142
// Get the type of the body
4243
bodyType := goreflect.GetTypeOf(body)
4344

45+
// Dereference the body type if it is a pointer
46+
if bodyType.Kind() == reflect.Pointer {
47+
bodyType = bodyType.Elem()
48+
}
49+
4450
// Create the mapper
4551
mapper, err := m.generator.NewMapper(body)
4652
if err != nil {

0 commit comments

Comments
 (0)