File tree 4 files changed +17
-10
lines changed
4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change
1
+ package globals
2
+
3
+ var Body string = ""
Original file line number Diff line number Diff line change 4
4
"encoding/base64"
5
5
"fmt"
6
6
"jamq-replica/constants"
7
+ "jamq-replica/globals"
7
8
"net/http"
8
9
"os"
9
10
"strconv"
@@ -14,15 +15,18 @@ import (
14
15
"crypto/sha256"
15
16
16
17
"github.com/labstack/echo/v4"
18
+ "github.com/valyala/bytebufferpool"
17
19
)
18
20
19
21
func Authenticate (next echo.HandlerFunc ) echo.HandlerFunc {
20
22
return func (c echo.Context ) error {
21
- var bodyBytes [] byte
23
+ bodyBytesBuffer := & bytebufferpool. ByteBuffer {}
22
24
request := c .Request ()
23
25
header := request .Header
24
- request .Body .Read (bodyBytes )
25
- body := string (bodyBytes )
26
+ bodyBytesBuffer .ReadFrom (request .Body )
27
+ body := bodyBytesBuffer .String ()
28
+ globals .Body = body
29
+ fmt .Println ("Body is: " + body )
26
30
queryString := strings .ToValidUTF8 (c .QueryString (), "" )
27
31
nonce := header .Get (constants .GetHeaders ().X_AUTH_NONCE )
28
32
sentTimestamp , err := strconv .Atoi (nonce )
Original file line number Diff line number Diff line change 1
1
package utils
2
2
3
3
import (
4
- "bytes"
5
4
"encoding/json"
6
-
7
- "github.com/labstack/echo/v4"
5
+ "jamq-replica/globals"
8
6
)
9
7
10
- func GetRequestBody (c echo.Context , requestBody interface {}) error {
11
- bytesBuff := new (bytes.Buffer )
12
- bytesBuff .ReadFrom (c .Request ().Body )
13
- err := json .Unmarshal (bytesBuff .Bytes (), requestBody )
8
+ func GetRequestBody (requestBody interface {}) error {
9
+ err := json .Unmarshal ([]byte (globals .Body ), requestBody )
14
10
return err
15
11
}
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ func HandleSendMessage(c echo.Context) error {
43
43
if err != nil {
44
44
return echo .NewHTTPError (400 , err .Error ())
45
45
}
46
+ err = utils .GetRequestBody (request )
47
+ if err != nil {
48
+ return echo .NewHTTPError (400 , err .Error ())
49
+ }
46
50
err = queueService .SendMessage (c .Param ("queueName" ), request .Message , request .Timestamp )
47
51
if err != nil {
48
52
return echo .NewHTTPError (400 , err .Error ())
You can’t perform that action at this time.
0 commit comments