-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_result.go
55 lines (45 loc) · 1.57 KB
/
rest_result.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
package winter
import (
"net/http"
"strconv"
)
type RestResult struct {
Status int `json:"status"`
Code string `json:"code"`
Data any `json:"data"`
Message string `json:"message"`
}
func NewRestResult(
status int,
code string,
data any,
message string,
) *RestResult {
return &RestResult{
Status: status,
Code: code,
Data: data,
Message: message,
}
}
func NewSuccessRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusOK, strconv.Itoa(http.StatusOK), data, message)
}
func NewBadRequestRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusBadRequest, strconv.Itoa(http.StatusBadRequest), data, message)
}
func NewNotFoundRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusNotFound, strconv.Itoa(http.StatusNotFound), data, message)
}
func NewUnauthorizedRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusUnauthorized, strconv.Itoa(http.StatusUnauthorized), data, message)
}
func NewForbiddenRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusForbidden, strconv.Itoa(http.StatusForbidden), data, message)
}
func NewInternalServerErrorRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusInternalServerError, strconv.Itoa(http.StatusInternalServerError), data, message)
}
func NewServiceUnavailableRestResult(data any, message string) *RestResult {
return NewRestResult(http.StatusServiceUnavailable, strconv.Itoa(http.StatusServiceUnavailable), data, message)
}