Skip to content

Commit

Permalink
removing pointer from EquinoxRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Dec 9, 2023
1 parent 79ada8c commit a306368
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func NewInternalClient(config api.EquinoxConfig) (*Client, error) {
return client, nil
}

func (c *Client) Request(ctx context.Context, logger zerolog.Logger, baseURL string, httpMethod string, route any, path string, methodID string, body any) (*api.EquinoxRequest, error) {
func (c *Client) Request(ctx context.Context, logger zerolog.Logger, baseURL string, httpMethod string, route any, path string, methodID string, body any) (api.EquinoxRequest, error) {
if ctx == nil {
return nil, errContextIsNil
return api.EquinoxRequest{}, errContextIsNil
}

equinoxReq := &api.EquinoxRequest{
equinoxReq := api.EquinoxRequest{
Logger: logger,
MethodID: methodID,
Route: route,
Expand All @@ -100,30 +100,30 @@ func (c *Client) Request(ctx context.Context, logger zerolog.Logger, baseURL str
if equinoxReq.Body != nil {
bodyBytes, err := jsonv2.Marshal(equinoxReq.Body)
if err != nil {
return nil, err
return api.EquinoxRequest{}, err
}
buffer = bytes.NewReader(bodyBytes)
}

request, err := http.NewRequestWithContext(ctx, httpMethod, url, buffer)
if err != nil {
return nil, err
return api.EquinoxRequest{}, err
}
equinoxReq.IsCDN = slices.Contains(cdns, request.URL.Host)

if equinoxReq.IsCDN {
request.Header = cdnHeaders.Clone()
} else {
if c.key == "" {
return nil, errKeyNotProvided
return api.EquinoxRequest{}, errKeyNotProvided
}
request.Header = apiHeaders.Clone()
}
equinoxReq.Request = request
return equinoxReq, nil
}

func (c *Client) Execute(ctx context.Context, equinoxReq *api.EquinoxRequest, target any) error {
func (c *Client) Execute(ctx context.Context, equinoxReq api.EquinoxRequest, target any) error {
if ctx == nil {
return errContextIsNil
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (c *Client) Execute(ctx context.Context, equinoxReq *api.EquinoxRequest, ta
return jsonv2.Unmarshal(body, &target)
}

func (c *Client) checkResponse(equinoxReq *api.EquinoxRequest, response *http.Response) (time.Duration, error) {
func (c *Client) checkResponse(equinoxReq api.EquinoxRequest, response *http.Response) (time.Duration, error) {
if c.isRateLimitEnabled && !equinoxReq.IsCDN {
c.ratelimit.Update(equinoxReq.Logger, equinoxReq.Route, equinoxReq.MethodID, &response.Header)
}
Expand Down

0 comments on commit a306368

Please sign in to comment.