/
response.go
55 lines (45 loc) · 1.3 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package handler
import (
"fmt"
"net/http"
"github.com/erismaroliveira/gopportunities/schemas"
"github.com/gin-gonic/gin"
)
func sendError(ctx *gin.Context, code int, msg string) {
ctx.Header("Content-Type", "application/json")
ctx.JSON(code, gin.H{
"message": msg,
"errorCode": code,
})
}
func sendSuccess(ctx *gin.Context, op string, data interface{}) {
ctx.Header("Content-Type", "application/json")
ctx.JSON(http.StatusOK, gin.H{
"message": fmt.Sprintf("operation from handler: %s successfull", op),
"data": data,
})
}
type ErrorResponse struct {
Message string `json:"message"`
ErrorCode string `json:"errorCode"`
}
type CreateOpeningResponse struct {
Message string `json:"message"`
Data schemas.OpeningResponse `json:"data"`
}
type DeleteOpeningResponse struct {
Message string `json:"message"`
Data schemas.OpeningResponse `json:"data"`
}
type ShowOpeningResponse struct {
Message string `json:"message"`
Data schemas.OpeningResponse `json:"data"`
}
type ListOpeningsResponse struct {
Message string `json:"message"`
Data []schemas.OpeningResponse `json:"data"`
}
type UpdateOpeningResponse struct {
Message string `json:"message"`
Data schemas.OpeningResponse `json:"data"`
}