Skip to content

Commit

Permalink
improve fetch.Empty recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
glossd committed Dec 1, 2024
1 parent dff7981 commit 354dc11
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion to_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ToHandlerFunc[In any, Out any](apply ApplyFunc[In, Out]) http.HandlerFunc {
return
}
var in In
if reflect.TypeFor[In]() != reflect.TypeOf(Empty{}) {
if st, _ := isStructType(in); st != reflect.TypeOf(Empty{}) {
reqBody, err := io.ReadAll(r.Body)
if err != nil {
cfg.ErrorHook(err)
Expand Down Expand Up @@ -129,8 +129,15 @@ func shouldValidateInput(v any) bool {

func isStructType(v any) (reflect.Type, bool) {
typeOf := reflect.TypeOf(v)
if v == nil {
return typeOf, false
}
switch typeOf.Kind() {
case reflect.Pointer:
valueOf := reflect.ValueOf(v)
if valueOf.IsNil() {
return typeOf, false
}
t := reflect.ValueOf(v).Elem().Type()
return t, t.Kind() == reflect.Struct
case reflect.Struct:
Expand Down

0 comments on commit 354dc11

Please sign in to comment.