moodlink-gofiber / utils /response.go
chandafa's picture
deployment v0.1
1b18b9e
raw
history blame contribute delete
631 Bytes
package utils
import (
"github.com/gofiber/fiber/v2"
)
type Response struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
}
func SuccessResponse(c *fiber.Ctx, data interface{}) error {
return c.JSON(Response{
Status: "success",
Data: data,
})
}
func ErrorResponse(c *fiber.Ctx, status int, message string) error {
return c.Status(status).JSON(Response{
Status: "error",
Message: message,
})
}
func MessageResponse(c *fiber.Ctx, message string) error {
return c.JSON(Response{
Status: "success",
Message: message,
})
}