initial commit

This commit is contained in:
Hafizh A. Y
2025-09-25 10:46:46 +07:00
parent c43544e5e8
commit 10506238ae
64 changed files with 3564 additions and 0 deletions
+30
View File
@@ -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
}
+36
View File
@@ -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"`
}