-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreply.go
63 lines (49 loc) · 1.28 KB
/
reply.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
package hexa
type (
// Reply is reply to actions in microservices.
Reply interface {
// HTTPStatus returns the http status code for the reply.
HTTPStatus() int
// SetHTTPStatus sets the http status code for the reply.
SetHTTPStatus(status int) Reply
// ID is reply identifier
ID() string
// Data returns the extra data of the reply (e.g show this data to user).
// Note: we use data as translation prams also.
Data() any
// SetData set the reply data as extra data of the reply to show to the user.
SetData(data any) Reply
}
// defaultReply implements the Reply interface.
defaultReply struct {
httpStatus int
id string
data any
}
)
func (r defaultReply) HTTPStatus() int {
return r.httpStatus
}
func (r defaultReply) SetHTTPStatus(status int) Reply {
r.httpStatus = status
return r
}
func (r defaultReply) ID() string {
return r.id
}
func (r defaultReply) Data() any {
return r.data
}
func (r defaultReply) SetData(data any) Reply {
r.data = data
return r
}
// NewReply returns new instance the Reply interface implemented by defaultReply.
func NewReply(httpStatus int, id string) Reply {
return defaultReply{
httpStatus: httpStatus,
id: id,
}
}
// Assert defaultReply implements the Error interface.
var _ Reply = defaultReply{}