-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathresponse.go
More file actions
51 lines (41 loc) · 987 Bytes
/
Copy pathresponse.go
File metadata and controls
51 lines (41 loc) · 987 Bytes
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
package timeout
import (
"github.com/gin-gonic/gin"
"net/http"
)
var defaultResponse = &BaseResponse{
Code: http.StatusServiceUnavailable,
Content: `{"code": -1, "msg":"http: Handler timeout"}`,
ContentType: "text/plain; charset=utf-8",
}
type Response interface {
GetCode(c *gin.Context) int
GetContent(c *gin.Context) any
GetContentType(c *gin.Context) string
SetCode(int)
SetContent(any)
SetContentType(string)
}
type BaseResponse struct {
Code int
Content any
ContentType string
}
func (r *BaseResponse) GetCode(c *gin.Context) int {
return r.Code
}
func (r *BaseResponse) GetContent(c *gin.Context) any {
return r.Content
}
func (r *BaseResponse) GetContentType(c *gin.Context) string {
return r.ContentType
}
func (r *BaseResponse) SetCode(code int) {
r.Code = code
}
func (r *BaseResponse) SetContent(content any) {
r.Content = content
}
func (r *BaseResponse) SetContentType(contentType string) {
r.ContentType = contentType
}