-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonResponse.go
39 lines (35 loc) · 1.12 KB
/
JsonResponse.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
package pretty
// JSONResponse format
type JSONResponse struct {
StatusCode string `json:"status_code"`
StatusText string `json:"status_text"`
Message string `json:"message"`
Data interface{} `json:"data"`
Paginator map[string]int `json:"paginator"`
}
// Simple Response
func (r *JSONResponse) Simple(statusCode string, statusText string, message string) {
r.StatusCode = statusCode
r.StatusText = statusText
r.Message = message
}
// WithData Response
func (r *JSONResponse) WithData(statusCode string, statusText string, message string, data interface{}) {
r.StatusCode = statusCode
r.StatusText = statusText
r.Message = message
r.Data = data
}
// WithData Response
func (r *JSONResponse) WithPagination(statusCode string, statusText string, message string, data interface{}, paginator map[string]int) {
r.StatusCode = statusCode
r.StatusText = statusText
r.Message = message
r.Data = data
r.Paginator = map[string]int{
"per_page": paginator["PageSize"],
"current_page": paginator["Page"],
"previous_page": paginator["Page"] - 1,
"next_page": paginator["Page"] + 1,
}
}