first commit

This commit is contained in:
2023-04-15 16:23:34 +07:00
commit bbed7f94f4
20 changed files with 533 additions and 0 deletions

32
helper/reponse.go Normal file
View 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)
}