/
type.go
48 lines (39 loc) · 992 Bytes
/
type.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
package response
import "time"
type (
// APIResponse is to be implemented for sending a response to the client
APIResponse interface {
Data() interface{}
}
// APIError is to be implemented for sending an error to the client
APIError interface {
Message() string
Code() ErrorCode
Data() interface{}
}
)
type (
response struct {
RequestID string `json:"request_id"`
Timestamp time.Time `json:"timestamp"`
URI string `json:"uri"`
Success bool `json:"success"`
Data interface{} `json:"data"`
Error *errorWrap `json:"error"`
}
errorWrap struct {
Message string `json:"message"`
Code ErrorCode `json:"code"`
Data interface{} `json:"data"`
}
defaultErr struct{}
)
func (d *defaultErr) Message() string {
return "An unknown error occurred. If this persists, please contact us."
}
func (d *defaultErr) Code() ErrorCode {
return DefaultErrorCode
}
func (d *defaultErr) Data() interface{} {
return nil
}