blob: 2c13218cbc2b5833c71a1bc22fa15286d908683a (
plain)
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
|
package dto
import "fmt"
type Response interface {
Error() string
Status() int
}
type OkResponse struct {
Code int `json:"code"`
Data interface{} `json:"data,omitempty"`
}
var _ Response = (*OkResponse)(nil)
type ErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}
var _ Response = (*ErrorResponse)(nil)
func (r *OkResponse) Status() int {
return r.Code
}
func (r *OkResponse) Error() string {
return fmt.Sprintf("HTTP status %d", r.Code)
}
func (r *ErrorResponse) Status() int {
return r.Code
}
func (r *ErrorResponse) Error() string {
return fmt.Sprintf("HTTP status %d: %s", r.Code, r.Message)
}
|