first commit
This commit is contained in:
32
helper/reponse.go
Normal file
32
helper/reponse.go
Normal file
@ -0,0 +1,32 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ResponseData : response format
|
||||
type ResponseData struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// RespondJSON : send a proper response json to the client
|
||||
func RespondJSON(w *gin.Context, status int, message string, payload interface{}) {
|
||||
var res ResponseData
|
||||
|
||||
if status >= 200 && status < 300 {
|
||||
res.Success = true
|
||||
}
|
||||
|
||||
if len(message) != 0 {
|
||||
res.Message = message
|
||||
}
|
||||
|
||||
if payload != nil {
|
||||
res.Data = payload
|
||||
}
|
||||
|
||||
w.JSON(http.StatusOK, res)
|
||||
}
|
Reference in New Issue
Block a user