-
Notifications
You must be signed in to change notification settings - Fork 0
/
interceptors.go
34 lines (28 loc) · 913 Bytes
/
interceptors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package jsonrpc
import (
"context"
"encoding/json"
)
//InterceptorCallMethod interface for interceptor method
type InterceptorCallMethod func(ctx context.Context,
methodName string,
data json.RawMessage,
id interface{}) (context.Context, int, error)
//InterceptorCallMethods registry for global interceptors
type InterceptorCallMethods []InterceptorCallMethod
//RegisterGlobalInterceptorCall register global interceptors
func (j *JSONRPC) RegisterGlobalInterceptorCall(method InterceptorCallMethod) {
j.globalInterceptors = append(j.globalInterceptors, method)
}
func (j *JSONRPC) callGlobalInterceptors(ctx context.Context,
methodName string,
data json.RawMessage,
id interface{}) (context.Context, int, error) {
for _, interceptor := range j.globalInterceptors {
ctx, code, err := interceptor(ctx, methodName, data, id)
if err != nil {
return ctx, code, err
}
}
return ctx, OK, nil
}