Skip to content

Commit 46e9359

Browse files
committed
fix: Backwards compability on return types for liman
1 parent 924fe05 commit 46e9359

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

app/handlers/extension.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ func ExtensionRunner(c *fiber.Ctx) error {
7575

7676
output := linux.Execute(command)
7777

78-
if helpers.LimanJSON(output) {
78+
if helpers.IsJSON(output) {
7979
type LimanMessage struct {
80-
Message string `json:"message"`
81-
Status int `json:"status"`
80+
Message any `json:"message"`
81+
Status int `json:"status"`
8282
}
8383
msg := &LimanMessage{}
8484

@@ -87,9 +87,15 @@ func ExtensionRunner(c *fiber.Ctx) error {
8787
return c.Type("json").SendString(output)
8888
}
8989

90-
if msg != nil && msg.Status > 200 {
90+
if msg != nil && msg.Status > 399 {
9191
return c.Status(201).Type("json").SendString(output)
9292
}
93+
94+
if msg != nil {
95+
return c.Status(msg.Status).Type("json").SendString(output)
96+
}
97+
98+
return c.Type("json").SendString(output)
9399
}
94100

95101
return c.SendString(output)

app/handlers/external.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ func ExternalAPI(c *fiber.Ctx) error {
7878
}
7979

8080
output := linux.Execute(command)
81-
if helpers.LimanJSON(output) {
81+
if helpers.IsJSON(output) {
8282
type LimanMessage struct {
83-
Message string `json:"message"`
84-
Status int `json:"status"`
83+
Message any `json:"message"`
84+
Status int `json:"status"`
8585
}
8686
msg := &LimanMessage{}
8787

@@ -90,9 +90,15 @@ func ExternalAPI(c *fiber.Ctx) error {
9090
return c.Type("json").SendString(output)
9191
}
9292

93-
if msg != nil && msg.Status > 200 {
93+
if msg != nil && msg.Status > 399 {
9494
return c.Status(201).Type("json").SendString(output)
9595
}
96+
97+
if msg != nil {
98+
return c.Status(msg.Status).Type("json").SendString(output)
99+
}
100+
101+
return c.Type("json").SendString(output)
96102
}
97103

98104
return c.SendString(output)

app/middleware/app_logger/new.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package app_logger
22

33
import (
4+
"strings"
5+
46
"github.com/gofiber/fiber/v2"
57
"github.com/google/uuid"
68
"github.com/limanmys/render-engine/pkg/helpers"
@@ -40,6 +42,12 @@ func New() fiber.Handler {
4042

4143
formData := helpers.GetFormData(c)
4244

45+
for k := range formData {
46+
if strings.Contains(strings.ToLower(k), "password") || strings.Contains(strings.ToLower(k), "token") {
47+
formData[k] = ""
48+
}
49+
}
50+
4351
user_id := ""
4452
if c.Locals("user_id") != nil {
4553
user_id = c.Locals("user_id").(string)

internal/server/error_handler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package server
22

33
import (
4+
"strings"
5+
46
"github.com/gofiber/fiber/v2"
57
"github.com/limanmys/render-engine/pkg/helpers"
68
"github.com/limanmys/render-engine/pkg/logger"
@@ -23,6 +25,12 @@ var ErrorHandler = func(c *fiber.Ctx, err error) error {
2325
if code >= fiber.StatusInternalServerError {
2426
request := helpers.GetFormData(c)
2527

28+
for k := range request {
29+
if strings.Contains(strings.ToLower(k), "password") || strings.Contains(strings.ToLower(k), "token") {
30+
request[k] = ""
31+
}
32+
}
33+
2634
logger.Sugar().WithOptions(zap.WithCaller(false)).Errorw(
2735
"recover middleware catch",
2836
"status", code,

pkg/helpers/form.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package helpers
22

33
import (
44
"net/url"
5-
"strings"
65

76
"github.com/gofiber/fiber/v2"
87
)
@@ -22,10 +21,6 @@ func GetFormData(c *fiber.Ctx) map[string]string {
2221
continue
2322
}
2423

25-
if strings.Contains(strings.ToLower(key), "password") || strings.Contains(strings.ToLower(key), "token") {
26-
continue
27-
}
28-
2924
if len(value) > 0 {
3025
formValues[key] = value[0]
3126
}
@@ -42,10 +37,6 @@ func BodyParser(body []byte) map[string]string {
4237

4338
obj := map[string]string{}
4439
for k, v := range values {
45-
if strings.Contains(strings.ToLower(k), "password") || strings.Contains(strings.ToLower(k), "token") {
46-
continue
47-
}
48-
4940
if len(v) > 0 {
5041
obj[k] = v[0]
5142
}

0 commit comments

Comments
 (0)