lifedebugger commited on
Commit
dcf8f1f
·
verified ·
1 Parent(s): 37ed3a9

Delete utils

Browse files
Files changed (4) hide show
  1. utils/Logger.go +0 -28
  2. utils/api_response.go +0 -53
  3. utils/helper.go +0 -11
  4. utils/util.go +0 -9
utils/Logger.go DELETED
@@ -1,28 +0,0 @@
1
- package utils
2
-
3
- import (
4
- "log"
5
- "os"
6
-
7
- "pweb-api.abdanhafidz.com/config"
8
- )
9
-
10
- func LogError(errorLogged error) {
11
- log.Println("Error Log :", errorLogged)
12
-
13
- _, err := os.Stat(config.LOG_PATH + "/error_log.txt")
14
- if os.IsNotExist(err) {
15
- _, err = os.Create(config.LOG_PATH + "/error_log.txt")
16
- if err != nil {
17
- log.Fatalf("Gagal buka file log: %v", err)
18
- }
19
- }
20
-
21
- file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
22
-
23
- if err != nil {
24
- log.Fatalf("Gagal buka file log: %v", err)
25
- }
26
-
27
- log.SetOutput(file)
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/api_response.go DELETED
@@ -1,53 +0,0 @@
1
- package utils
2
-
3
- import (
4
- "net/http"
5
- "reflect"
6
-
7
- "pweb-api.abdanhafidz.com/models"
8
- "pweb-api.abdanhafidz.com/services"
9
-
10
- "github.com/gin-gonic/gin"
11
- )
12
-
13
- func ResponseOK(c *gin.Context, data any) {
14
- res := models.SuccessResponse{
15
- Status: "success",
16
- Message: "Data retrieved successfully!",
17
- Data: data,
18
- MetaData: c.Request.Body,
19
- }
20
- c.JSON(http.StatusOK, res)
21
- return
22
- }
23
-
24
- func ResponseFAIL(c *gin.Context, status int, exception models.Exception) {
25
- message := exception.Message
26
- exception.Message = ""
27
- res := models.ErrorResponse{
28
- Status: "error",
29
- Message: message,
30
- Errors: exception,
31
- MetaData: c.Request.Body,
32
- }
33
- c.AbortWithStatusJSON(status, res)
34
- return
35
- }
36
-
37
- func SendResponse(c *gin.Context, data services.Service[any, any]) {
38
- if reflect.ValueOf(data.Exception).IsNil() {
39
- ResponseOK(c, data)
40
- } else {
41
- if data.Exception.Unauthorized {
42
- ResponseFAIL(c, 401, data.Exception)
43
- } else if data.Exception.BadRequest {
44
- ResponseFAIL(c, 400, data.Exception)
45
- } else if data.Exception.DataNotFound {
46
- ResponseFAIL(c, 404, data.Exception)
47
- } else if data.Exception.InternalServerError {
48
- ResponseFAIL(c, 500, data.Exception)
49
- } else {
50
- ResponseFAIL(c, 403, data.Exception)
51
- }
52
- }
53
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/helper.go DELETED
@@ -1,11 +0,0 @@
1
- package utils
2
-
3
- import (
4
- "github.com/gin-gonic/gin"
5
- "pweb-api.abdanhafidz.com/models"
6
- )
7
-
8
- func GetAccount(c *gin.Context) models.AccountData {
9
- cParam, _ := c.Get("accountData")
10
- return cParam.(models.AccountData)
11
- }
 
 
 
 
 
 
 
 
 
 
 
 
utils/util.go DELETED
@@ -1,9 +0,0 @@
1
- package utils
2
-
3
- func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string {
4
- if condition {
5
- return valueIfTrue
6
- } else {
7
- return valueIfFalse
8
- }
9
- }