add header content type for OP

This commit is contained in:
Sinh 2022-10-04 16:29:34 +07:00
parent d3a7fe684b
commit 04cc91bb5f
4 changed files with 18 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/thoas/go-funk" "github.com/thoas/go-funk"
"github.com/Selly-Modules/3pl/util/base64" "github.com/Selly-Modules/3pl/util/base64"
"github.com/Selly-Modules/3pl/util/httputil"
"github.com/Selly-Modules/3pl/util/pjson" "github.com/Selly-Modules/3pl/util/pjson"
) )
@ -72,7 +73,7 @@ func (c *Client) CreateOrder(data CreateOrderPayload) (*CreateOrderResponseDecod
Method: http.MethodPost, Method: http.MethodPost,
Data: pjson.ToJSONString(body), Data: pjson.ToJSONString(body),
Header: map[string]string{ Header: map[string]string{
"Content-Type": "application/json", httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON,
}, },
}, },
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/Selly-Modules/natsio/model" "github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject" "github.com/Selly-Modules/natsio/subject"
"github.com/Selly-Modules/3pl/util/httputil"
"github.com/Selly-Modules/3pl/util/pjson" "github.com/Selly-Modules/3pl/util/pjson"
) )
@ -174,6 +175,7 @@ func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp, res int
headerXAPIKey: c.apiKey, headerXAPIKey: c.apiKey,
headerXSignature: sign, headerXSignature: sign,
headerXTimestamp: ts, headerXTimestamp: ts,
httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON,
} }
return ec.Request(subject.Communication.RequestHTTP, data, res) return ec.Request(subject.Communication.RequestHTTP, data, res)

View File

@ -12,6 +12,7 @@ import (
"github.com/Selly-Modules/natsio/subject" "github.com/Selly-Modules/natsio/subject"
"github.com/nats-io/nats.go" "github.com/nats-io/nats.go"
"github.com/Selly-Modules/3pl/util/httputil"
"github.com/Selly-Modules/3pl/util/pjson" "github.com/Selly-Modules/3pl/util/pjson"
) )
@ -230,7 +231,7 @@ func (c *Client) auth() (*authRes, error) {
body := v.Encode() body := v.Encode()
header := map[string]string{ header := map[string]string{
"Content-Type": "application/x-www-form-urlencoded", httputil.HeaderKeyContentType: httputil.HeaderValueApplicationURLEncoded,
} }
apiURL := baseURLAuthENVMapping[c.env] + fmt.Sprintf(apiPathAuth, c.realm) apiURL := baseURLAuthENVMapping[c.env] + fmt.Sprintf(apiPathAuth, c.realm)
natsPayload := model.CommunicationRequestHttp{ natsPayload := model.CommunicationRequestHttp{
@ -276,7 +277,7 @@ func (c *Client) auth() (*authRes, error) {
func (c *Client) getRequestHeader() map[string]string { func (c *Client) getRequestHeader() map[string]string {
m := map[string]string{ m := map[string]string{
"Content-Type": "application/json", httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON,
} }
token, err := c.getToken() token, err := c.getToken()
if err != nil { if err != nil {

8
util/httputil/const.go Normal file
View File

@ -0,0 +1,8 @@
package httputil
const (
HeaderKeyContentType = "Content-Type"
HeaderValueApplicationJSON = "application/json"
HeaderValueApplicationURLEncoded = "application/x-www-form-urlencoded"
)