forked from TarsCloud/TarsGo
-
Notifications
You must be signed in to change notification settings - Fork 4
/
filter.go
37 lines (27 loc) · 1.18 KB
/
filter.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
35
36
37
package tars
import (
"context"
"time"
"tars/protocol/res/requestf"
)
type filters struct {
cf ClientFilter
sf ServerFilter
}
var allFilters = filters{nil, nil}
//Invoke is used for Invoke tars server service
type Invoke func(ctx context.Context, msg *Message, timeout time.Duration) (err error)
//RegisterClientFilter registers the Client filter , and will be executed in every request.
func RegisterClientFilter(f ClientFilter) {
allFilters.cf = f
}
//Dispatch server side Dispatch
type Dispatch func(context.Context, interface{}, *requestf.RequestPacket, *requestf.ResponsePacket, bool) error
//ServerFilter is used for add Filter for server dispatcher ,for implementing plugins like opentracing.
type ServerFilter func(ctx context.Context, d Dispatch, f interface{}, req *requestf.RequestPacket, resp *requestf.ResponsePacket, withContext bool) (err error)
//ClientFilter is used for filter request & response for client, for implementing plugins like opentracing
type ClientFilter func(ctx context.Context, msg *Message, invoke Invoke, timeout time.Duration) (err error)
//RegisterServerFilter register the server filter.
func RegisterServerFilter(f ServerFilter) {
allFilters.sf = f
}