pkg/common/helpers.go   A
last analyzed

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 16
dl 0
loc 33
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A common.RespondCreated 0 2 1
A common.RespondOk 0 2 1
A common.RespondWithData 0 3 1
A common.RespondOkWithData 0 2 1
A common.RespondError 0 3 1
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