-
Notifications
You must be signed in to change notification settings - Fork 182
/
seata_filter.go
43 lines (35 loc) · 946 Bytes
/
seata_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
38
39
40
41
42
43
package filter
import (
"context"
)
import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter"
"github.com/apache/dubbo-go/protocol"
)
const (
SEATA = "seata"
SEATA_XID = "seata_xid"
)
func init() {
extension.SetFilter(SEATA, getSeataFilter)
}
// SeataFilter ...
type SeataFilter struct {
}
// Invoke ...
func (sf *SeataFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
xid := invocation.AttachmentsByKey(SEATA_XID, "")
if xid != "" {
return invoker.Invoke(context.WithValue(ctx, SEATA_XID, xid), invocation)
}
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (sf *SeataFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetSeataFilter ...
func getSeataFilter() filter.Filter {
return &SeataFilter{}
}