28 lines
545 B
Go
28 lines
545 B
Go
|
package response
|
||
|
|
||
|
import "github.com/gofiber/fiber/v2"
|
||
|
|
||
|
type ResponseData struct {
|
||
|
Code ResponseCode `json:"code"`
|
||
|
Message string `json:"message"`
|
||
|
Data interface{} `json:"data"`
|
||
|
}
|
||
|
|
||
|
func Ok(c *fiber.Ctx, data interface{}) error {
|
||
|
ret := ResponseData{
|
||
|
Code: Success,
|
||
|
Message: Success.String(),
|
||
|
Data: data,
|
||
|
}
|
||
|
return c.JSON(ret)
|
||
|
}
|
||
|
|
||
|
func Error(c *fiber.Ctx, errCode ResponseCode, data interface{}) error {
|
||
|
ret := ResponseData{
|
||
|
Code: errCode,
|
||
|
Message: errCode.String(),
|
||
|
Data: data,
|
||
|
}
|
||
|
return c.JSON(ret)
|
||
|
}
|