Spaces:
Runtime error
Runtime error
Delete utils
Browse filesFiles changed (4)
- utils/Logger.goDeleted-28
- utils/api_response.goDeleted-53
- utils/helper.goDeleted-11
- utils/util.goDeleted-9
12345678910111213141516171819202122232425262728package utils
import (
"log"
"os"
"pweb-api.abdanhafidz.com/config"
)
func LogError(errorLogged error) {
log.Println("Error Log :", errorLogged)
_, err := os.Stat(config.LOG_PATH + "/error_log.txt")
if os.IsNotExist(err) {
_, err = os.Create(config.LOG_PATH + "/error_log.txt")
if err != nil {
log.Fatalf("Gagal buka file log: %v", err)
}
}
file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatalf("Gagal buka file log: %v", err)
}
log.SetOutput(file)
}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253package utils
import (
"net/http"
"reflect"
"pweb-api.abdanhafidz.com/models"
"pweb-api.abdanhafidz.com/services"
"github.com/gin-gonic/gin"
)
func ResponseOK(c *gin.Context, data any) {
res := models.SuccessResponse{
Status: "success",
Message: "Data retrieved successfully!",
Data: data,
MetaData: c.Request.Body,
}
c.JSON(http.StatusOK, res)
return
}
func ResponseFAIL(c *gin.Context, status int, exception models.Exception) {
message := exception.Message
exception.Message = ""
res := models.ErrorResponse{
Status: "error",
Message: message,
Errors: exception,
MetaData: c.Request.Body,
}
c.AbortWithStatusJSON(status, res)
return
}
func SendResponse(c *gin.Context, data services.Service[any, any]) {
if reflect.ValueOf(data.Exception).IsNil() {
ResponseOK(c, data)
} else {
if data.Exception.Unauthorized {
ResponseFAIL(c, 401, data.Exception)
} else if data.Exception.BadRequest {
ResponseFAIL(c, 400, data.Exception)
} else if data.Exception.DataNotFound {
ResponseFAIL(c, 404, data.Exception)
} else if data.Exception.InternalServerError {
ResponseFAIL(c, 500, data.Exception)
} else {
ResponseFAIL(c, 403, data.Exception)
}
}
}1234567891011package utils
import (
"github.com/gin-gonic/gin"
"pweb-api.abdanhafidz.com/models"
)
func GetAccount(c *gin.Context) models.AccountData {
cParam, _ := c.Get("accountData")
return cParam.(models.AccountData)
}123456789package utils
func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string {
if condition {
return valueIfTrue
} else {
return valueIfFalse
}
}utils/Logger.goDeleted-28
utils/api_response.goDeleted-53
utils/helper.goDeleted-11
utils/util.goDeleted-9