Skip to content

Commit d563e91

Browse files
authored
Merge pull request smallnest#905 from cuiweixie/reflect.TypeFor
code opt: refactor to use reflect.TypeFor
2 parents ea032f3 + 0b77d8c commit d563e91

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

โ€Žreflection/server_reflection.goโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
)
1717

1818
var (
19-
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
20-
typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
19+
typeOfError = reflect.TypeFor[error]()
20+
typeOfContext = reflect.TypeFor[context.Context]()
2121
)
2222

2323
// ServiceInfo service info.

โ€Žserver/service.goโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func (e RpcServiceInternalError) String() string {
3535

3636
// Precompute the reflect type for error. Can't use error directly
3737
// because Typeof takes an empty interface value. This is annoying.
38-
var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
38+
var typeOfError = reflect.TypeFor[error]()
3939

4040
// Precompute the reflect type for context.
41-
var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
41+
var typeOfContext = reflect.TypeFor[context.Context]()
4242

4343
type methodType struct {
4444
sync.Mutex // protects counters

0 commit comments

Comments
ย (0)