package machine
import (
"os"
"reflect"
)
type handlerReflect struct {
h any
methods *reflect .Value
methodCache map [string ]reflect .Value
missingCache map [string ]struct {}
}
type handlerCallReflect struct {
fn *reflect .Value
}
func newHandlerCallStruct(
e *Event , h *handler , methodName string , m *Machine ,
) *handlerCall {
_ , ok := h .refl .missingCache [methodName ]
if ok {
h .mx .Unlock ()
return nil
}
method , ok := h .refl .methodCache [methodName ]
if !ok {
method = h .refl .methods .MethodByName (methodName )
if !method .IsValid () {
method = h .refl .methods .Elem ().FieldByName (methodName )
}
if !method .IsValid () {
h .refl .missingCache [methodName ] = struct {}{}
h .mx .Unlock ()
return nil
}
h .refl .methodCache [methodName ] = method
}
h .mx .Unlock ()
m .log (LogOps , "[handler:%d] %s" , h .num , methodName )
m .currentHandler .Store (methodName )
m .tracersMx .RLock ()
for i := range m .tracers {
m .tracers [i ].HandlerStart (m .t .Load (), h .id , methodName )
}
m .tracersMx .RUnlock ()
c := &handlerCall {
refl : handlerCallReflect {fn : &method },
name : methodName ,
event : e ,
timeout : false ,
}
if os .Getenv (EnvAmDetectEval ) != "" {
c .debug = h .id + "." + methodName
}
return c
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .