Skip to content

Commit

Permalink
simplified client code to use a singleton client
Browse files Browse the repository at this point in the history
  • Loading branch information
MarketDataApp committed Feb 19, 2024
1 parent 6e91a9f commit c8ac9b0
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 169 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![License](https://img.shields.io/github/license/MarketDataApp/sdk-go.svg)](https://github.com/MarketDataApp/sdk-go/blob/master/LICENSE)
![SDK Version](https://img.shields.io/badge/version-1.0.0-blue.svg)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/MarketDataApp/sdk-go)
![Lines of Code](https://img.shields.io/badge/lines_of_code-8585-blue)
![Lines of Code](https://img.shields.io/badge/lines_of_code-8608-blue)

#### Connect With The Market Data Community

Expand Down
23 changes: 8 additions & 15 deletions baseRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func (br *baseRequest) getPath() (string, error) {
if br == nil {
return "", fmt.Errorf("path is nil")
}

if br.path == "" {
return "", fmt.Errorf("path is empty")
}

return br.path, nil
}

Expand Down Expand Up @@ -246,29 +251,17 @@ func (br *baseRequest) getError() error {
return br.Error
}

// Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient
// to be passed which, if provided, replaces the client used in the request.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided,
// the first MarketDataClient in the slice replaces the current client for this request.
// Raw executes the request and returns the raw resty.Response.
//
// # Returns
//
// - *resty.Response: The raw response from the executed request.
// - error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (request *baseRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
// - error: An error object if the baseRequest is nil, or if an error occurs during the request execution.
func (request *baseRequest) Raw() (*resty.Response, error) {
if request == nil {
return nil, fmt.Errorf("baseRequest is nil")
}

// Replace the client if an optional client is provided
if len(optionalClients) > 0 && optionalClients[0] != nil {
request.client = optionalClients[0]
}

// Check if the client is nil after potentially replacing it
if request.client == nil {
return nil, fmt.Errorf("MarketDataClient is nil")
}
Expand Down
Loading

0 comments on commit c8ac9b0

Please sign in to comment.