code opt: refactor to use reflect.TypeFor

This commit is contained in:
cuiweixie
2025-08-22 16:49:17 +08:00
parent ea032f3b9d
commit 0b77d8c4a4
2 changed files with 4 additions and 4 deletions

View File

@@ -16,8 +16,8 @@ import (
)
var (
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
typeOfError = reflect.TypeFor[error]()
typeOfContext = reflect.TypeFor[context.Context]()
)
// ServiceInfo service info.

View File

@@ -35,10 +35,10 @@ func (e RpcServiceInternalError) String() string {
// Precompute the reflect type for error. Can't use error directly
// because Typeof takes an empty interface value. This is annoying.
var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
var typeOfError = reflect.TypeFor[error]()
// Precompute the reflect type for context.
var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
var typeOfContext = reflect.TypeFor[context.Context]()
type methodType struct {
sync.Mutex // protects counters