Skip to content

Commit ad8b0f2

Browse files
committed
♻️ refactor: updated codebase #2
1 parent a68cce4 commit ad8b0f2

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/go-playground/universal-translator v0.18.1
99
github.com/go-playground/validator/v10 v10.14.0
1010
github.com/go-redis/redis v6.15.9+incompatible
11-
github.com/sivaosorg/govm v1.2.6
11+
github.com/sivaosorg/govm v1.2.7
1212
github.com/sivaosorg/mysqlconn v1.0.3
1313
github.com/sivaosorg/postgresconn v1.0.5
1414
github.com/sivaosorg/redisconn v1.0.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
120120
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
121121
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
122122
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
123-
github.com/sivaosorg/govm v1.2.6 h1:BCUCNk/yy/rFZ+clMF7ftfw99ZQFO+4QSFV/xe2mWfA=
124-
github.com/sivaosorg/govm v1.2.6/go.mod h1:rXfPCNGc4ddPf1+VRX8Ytw/5xqehfPRrCr53Oi+cwpw=
123+
github.com/sivaosorg/govm v1.2.7 h1:r2HZJDMmU4+BLkQ5h6aC6tn2JZ4A7p6S+khd1a23GAk=
124+
github.com/sivaosorg/govm v1.2.7/go.mod h1:rXfPCNGc4ddPf1+VRX8Ytw/5xqehfPRrCr53Oi+cwpw=
125125
github.com/sivaosorg/mysqlconn v1.0.3 h1:UoxFe0abN6jibkk+bH3rvsIh+vOacujgJDvSSgTk2kY=
126126
github.com/sivaosorg/mysqlconn v1.0.3/go.mod h1:NqGtpFwM1E09oTK9G5LOHx0nbtFUjHPTo5V9ob1xCto=
127127
github.com/sivaosorg/postgresconn v1.0.5 h1:/dWZrGdh09QIj7xjFjxs99SpBHk0RanIincazjdWSnU=

pkg/utils/collection.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

pkg/utils/request.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ package utils
33
import (
44
"bytes"
55
"io/ioutil"
6-
"strings"
76

87
"github.com/gin-gonic/gin"
8+
9+
"github.com/sivaosorg/govm/charge"
910
)
1011

1112
// SnapshotRequestBodyWith reads the request body and handles both form data and other types.
1213
// It returns the raw body as a byte slice.
1314
func SnapshotRequestBodyWith(ctx *gin.Context) ([]byte, error) {
1415
// Check if the request has a form content type
15-
if IsPostForm(ctx) {
16-
// err := ctx.Request.ParseForm()
17-
// if err != nil {
18-
// return nil, err
19-
// }
16+
if charge.IsPostForms(ctx.Request) {
2017
ctx.MultipartForm()
2118
// Form data is already parsed, so you can access it using ctx.Request.PostForm
2219
// Example: formData := ctx.Request.PostForm
@@ -32,18 +29,7 @@ func SnapshotRequestBodyWith(ctx *gin.Context) ([]byte, error) {
3229
return raw, err
3330
}
3431

35-
func IsPostForm(ctx *gin.Context) bool {
36-
value := ctx.Request.Header.Get("Content-Type")
37-
return value == "application/x-www-form-urlencoded" || strings.Contains(value, "multipart/form-data")
38-
}
39-
40-
func GetPostFromValues(ctx *gin.Context) map[string]string {
32+
func GetPostForms(ctx *gin.Context) map[string]string {
4133
ctx.MultipartForm()
42-
formValues := make(map[string]string)
43-
for key, values := range ctx.Request.PostForm {
44-
if len(values) > 0 {
45-
formValues[key] = values[0]
46-
}
47-
}
48-
return formValues
34+
return charge.GetPostForms(ctx.Request)
4935
}

0 commit comments

Comments
 (0)