forked from osuripple/api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
response.go
36 lines (30 loc) · 809 Bytes
/
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
package common
// ResponseBase is the data that is always returned with an API request.
type ResponseBase struct {
Code int `json:"code"`
Message string `json:"message,omitempty"`
}
// GetCode retrieves the response code.
func (r ResponseBase) GetCode() int {
return r.Code
}
// SetCode changes the response code.
func (r *ResponseBase) SetCode(i int) {
r.Code = i
}
// GetMessage retrieves the response message.
func (r ResponseBase) GetMessage() string {
return r.Message
}
// CodeMessager is something that has the Code() and Message() methods.
type CodeMessager interface {
GetMessage() string
GetCode() int
}
// SimpleResponse returns the most basic response.
func SimpleResponse(code int, message string) CodeMessager {
return ResponseBase{
Code: code,
Message: message,
}
}