mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-21 12:46:03 +03:00
add json unmarshaling helper
This commit is contained in:
parent
a2eb85eb25
commit
2d1b2351ee
@ -1,11 +1,13 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
// nolint:gosec
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -16,6 +18,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"github.com/gin-gonic/gin"
|
||||
retailcrm "github.com/retailcrm/api-client-go/v2"
|
||||
v1 "github.com/retailcrm/mg-transport-api-client-go/v1"
|
||||
|
||||
@ -281,3 +284,15 @@ func GetCurrencySymbol(code string) string {
|
||||
func FormatCurrencyValue(value float32) string {
|
||||
return fmt.Sprintf("%.2f", value)
|
||||
}
|
||||
|
||||
// BindJSONWithRaw will perform usual ShouldBindJSON and will return the original body data.
|
||||
func BindJSONWithRaw(c *gin.Context, obj any) ([]byte, error) {
|
||||
closer := c.Request.Body
|
||||
defer func() { _ = closer.Close() }()
|
||||
data, err := io.ReadAll(closer)
|
||||
if err != nil {
|
||||
return []byte, err
|
||||
}
|
||||
c.Request.Body = io.NopCloser(bytes.NewReader(data))
|
||||
return data, c.ShouldBindJSON(obj)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user