-
Notifications
You must be signed in to change notification settings - Fork 16
/
response.go
86 lines (72 loc) · 2.08 KB
/
response.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package kubemq
import (
"context"
"time"
)
type Response struct {
RequestId string
ResponseTo string
Metadata string
Body []byte
ClientId string
ExecutedAt time.Time
Err error
Tags map[string]string
transport Transport
trace *Trace
}
func NewResponse() *Response {
return &Response{}
}
// SetId - set response corresponded requestId - mandatory
func (r *Response) SetRequestId(id string) *Response {
r.RequestId = id
return r
}
// SetResponseTo - set response channel as received in CommandReceived or QueryReceived object - mandatory
func (r *Response) SetResponseTo(channel string) *Response {
r.ResponseTo = channel
return r
}
// SetMetadata - set metadata response, for query only
func (r *Response) SetMetadata(metadata string) *Response {
r.Metadata = metadata
return r
}
// SetMetadata - set body response, for query only
func (r *Response) SetBody(body []byte) *Response {
r.Body = body
return r
}
// SetTags - set response tags
func (r *Response) SetTags(tags map[string]string) *Response {
r.Tags = tags
return r
}
// SetClientID - set clientId response, if not set default clientId will be used
func (r *Response) SetClientId(clientId string) *Response {
r.ClientId = clientId
return r
}
// SetError - set query or command execution error
func (r *Response) SetError(err error) *Response {
r.Err = err
return r
}
// SetExecutedAt - set query or command execution time
func (r *Response) SetExecutedAt(executedAt time.Time) *Response {
r.ExecutedAt = executedAt
return r
}
// AddTrace - add tracing support to response
func (r *Response) AddTrace(name string) *Trace {
r.trace = CreateTrace(name)
return r.trace
}
// Send - sending response to command or query request
func (r *Response) Send(ctx context.Context) error {
return r.transport.SendResponse(ctx, r)
}
func (r *Response) String() string {
return "Response: RequestId: " + r.RequestId + ", ResponseTo: " + r.ResponseTo + ", Metadata: " + r.Metadata + ", Body: " + string(r.Body) + ", ClientId: " + r.ClientId + ", ExecutedAt: " + r.ExecutedAt.String() + ", Err: " + r.Err.Error()
}