Skip to content

Commit 7aef7ea

Browse files
authored
Refactor to use reflect.TypeFor (#35370)
1 parent 89cc966 commit 7aef7ea

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

modules/web/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var responseStatusProviders = map[reflect.Type]func(req *http.Request) types.ResponseStatusProvider{}
1717

1818
func RegisterResponseStatusProvider[T any](fn func(req *http.Request) types.ResponseStatusProvider) {
19-
responseStatusProviders[reflect.TypeOf((*T)(nil)).Elem()] = fn
19+
responseStatusProviders[reflect.TypeFor[T]()] = fn
2020
}
2121

2222
// responseWriter is a wrapper of http.ResponseWriter, to check whether the response has been written
@@ -48,8 +48,8 @@ func (r *responseWriter) WriteHeader(statusCode int) {
4848
}
4949

5050
var (
51-
httpReqType = reflect.TypeOf((*http.Request)(nil))
52-
respWriterType = reflect.TypeOf((*http.ResponseWriter)(nil)).Elem()
51+
httpReqType = reflect.TypeFor[*http.Request]()
52+
respWriterType = reflect.TypeFor[http.ResponseWriter]()
5353
)
5454

5555
// preCheckHandler checks whether the handler is valid, developers could get first-time feedback, all mistakes could be found at startup

0 commit comments

Comments
 (0)