Skip to content

Commit bde776d

Browse files
committed
fix: solved bug on Validate middleware function
1 parent 578805a commit bde776d

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

http/middleware/validator/middleware.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,17 @@ func (m *Middleware) Validate(
6060
panic(ErrNilCreateValidateFn)
6161
}
6262

63-
// Check if the type of the createValidateFn is a function and the parameters are correct
64-
fnValuePtr, paramsValuesPtr, err := goreflect.CheckFunction(
65-
createValidateFn,
66-
body,
67-
mapper,
68-
)
69-
if err != nil {
70-
panic(err)
71-
}
72-
73-
// Check if the parameters values are not nil
74-
if paramsValuesPtr == nil {
75-
panic(ErrNilParametersValues)
76-
}
77-
paramsValues := *paramsValuesPtr
78-
7963
return func(next http.Handler) http.Handler {
8064
return http.HandlerFunc(
8165
func(w http.ResponseWriter, r *http.Request) {
8266
// Get a new instance of the body
8367
dest := goreflect.NewInstanceFromType(bodyType)
8468

8569
// Call the validate function
86-
results, err := goreflect.UnsafeCallFunction(
87-
fnValuePtr,
88-
paramsValues...,
70+
results, err := goreflect.SafeCallFunction(
71+
createValidateFn,
72+
dest,
73+
mapper,
8974
)
9075
if err != nil {
9176
panic(err)

0 commit comments

Comments
 (0)