Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package common |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | |||
6 | "github.com/gin-gonic/gin" |
||
7 | ) |
||
8 | |||
9 | // RespondOk godoc |
||
10 | func RespondOk(c *gin.Context) { |
||
11 | RespondOkWithData(c, gin.H{"message": "OK"}) |
||
12 | } |
||
13 | |||
14 | // RespondOkWithData godoc |
||
15 | func RespondOkWithData(c *gin.Context, data interface{}) { |
||
16 | RespondWithData(c, http.StatusOK, data) |
||
17 | } |
||
18 | |||
19 | // RespondCreated godoc |
||
20 | func RespondCreated(c *gin.Context) { |
||
21 | RespondWithData(c, http.StatusCreated, gin.H{"message": "OK"}) |
||
22 | } |
||
23 | |||
24 | // RespondWithData godoc |
||
25 | func RespondWithData(c *gin.Context, httpStatusCode int, data interface{}) { |
||
26 | c.Header("Content-Type", "application/json") |
||
27 | c.JSON(httpStatusCode, data) |
||
28 | } |
||
29 | |||
30 | // RespondError godoc |
||
31 | func RespondError(c *gin.Context, httpStatusCode int, message interface{}) { |
||
32 | c.Header("Content-Type", "application/json") |
||
33 | c.AbortWithStatusJSON(httpStatusCode, gin.H{"error": message}) |
||
34 | } |
||
35 |