mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Error(c *fiber.Ctx, statusCode int, message string, details interface{}) error {
|
||||
var errRes error
|
||||
if details != nil {
|
||||
errRes = c.Status(statusCode).JSON(ErrorDetails{
|
||||
Code: statusCode,
|
||||
Status: "error",
|
||||
Message: message,
|
||||
Errors: details,
|
||||
})
|
||||
} else {
|
||||
errRes = c.Status(statusCode).JSON(Common{
|
||||
Code: statusCode,
|
||||
Status: "error",
|
||||
Message: message,
|
||||
})
|
||||
}
|
||||
|
||||
if errRes != nil {
|
||||
logrus.Errorf("Failed to send error response : %+v", errRes)
|
||||
}
|
||||
|
||||
return errRes
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package response
|
||||
|
||||
type Common struct {
|
||||
Code int `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type Success struct {
|
||||
Code int `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"limit"`
|
||||
TotalPages int64 `json:"total_pages"`
|
||||
TotalResults int64 `json:"total_results"`
|
||||
}
|
||||
|
||||
type SuccessWithPaginate[T any] struct {
|
||||
Code int `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
Meta Meta `json:"meta"`
|
||||
Data []T `json:"data"`
|
||||
}
|
||||
|
||||
type ErrorDetails struct {
|
||||
Code int `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
Errors interface{} `json:"errors"`
|
||||
}
|
||||
Reference in New Issue
Block a user