Merge pull request #905 from cuiweixie/reflect.TypeFor

code opt: refactor to use reflect.TypeFor
This commit is contained in:
smallnest
2025-08-26 09:47:45 +08:00
committed by GitHub
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