MCPcopy Create free account
hub / github.com/google/gapid / funcToHandler

Function funcToHandler

core/event/function.go:80–102  ·  view source on GitHub ↗
(ctx context.Context, f reflect.Value)

Source from the content-addressed store, hash-verified

78}
79
80func funcToHandler(ctx context.Context, f reflect.Value) Handler {
81 t, err := checkSignature(ctx, f.Type(),
82 []reflect.Type{contextType, nil},
83 []reflect.Type{errorType},
84 )
85 if err != nil {
86 log.F(ctx, true, "Checking handler signature. Error: %v", err)
87 }
88 return func(ctx context.Context, event interface{}) error {
89 args := []reflect.Value{
90 reflect.ValueOf(ctx),
91 safeValue(event, t),
92 }
93 if !args[1].Type().AssignableTo(t) {
94 return log.Errf(ctx, nil, "Invalid event type: %v. Expected: %v", args[1].Type(), t)
95 }
96 result := f.Call(args)
97 if !result[0].IsNil() {
98 return fault.From(result[0].Interface())
99 }
100 return nil
101 }
102}
103
104func funcToProducer(ctx context.Context, f reflect.Value) Producer {
105 _, err := checkSignature(ctx, f.Type(),

Callers 1

AsHandlerFunction · 0.85

Calls 8

checkSignatureFunction · 0.85
safeValueFunction · 0.85
FMethod · 0.80
ErrfMethod · 0.80
InterfaceMethod · 0.80
TypeMethod · 0.65
CallMethod · 0.65
IsNilMethod · 0.45

Tested by

no test coverage detected