Add context.Context parameter to all API methods
Enable request timeout and cancellation control by adding context.Context as the first parameter to all SDK API methods. This allows users to: - Set per-request timeouts - Cancel in-flight requests - Pass request-scoped values
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
||||
@@ -15,38 +16,38 @@ func NewTransactionClient(c *client.Client) *TransactionClient {
|
||||
return &TransactionClient{client: c}
|
||||
}
|
||||
|
||||
func (tc *TransactionClient) Create(req *models.TransactionCreateRequest) (*models.TransactionCreateResponse, error) {
|
||||
func (tc *TransactionClient) Create(ctx context.Context, req *models.TransactionCreateRequest) (*models.TransactionCreateResponse, error) {
|
||||
var resp models.TransactionCreateResponse
|
||||
err := tc.client.Post("/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
||||
err := tc.client.Post(ctx, "/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (tc *TransactionClient) CreateBulk(req *models.TransactionBulkRequest) (*models.TransactionBulkResponse, error) {
|
||||
func (tc *TransactionClient) CreateBulk(ctx context.Context, req *models.TransactionBulkRequest) (*models.TransactionBulkResponse, error) {
|
||||
var resp models.TransactionBulkResponse
|
||||
err := tc.client.Post("/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
||||
err := tc.client.Post(ctx, "/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (tc *TransactionClient) Get(transactionID string) (*models.Transaction, error) {
|
||||
func (tc *TransactionClient) Get(ctx context.Context, transactionID string) (*models.Transaction, error) {
|
||||
var resp models.Transaction
|
||||
path := fmt.Sprintf("/api/v1/transaction/%s", transactionID)
|
||||
err := tc.client.Get(path, &resp)
|
||||
err := tc.client.Get(ctx, path, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (tc *TransactionClient) List() (*models.ListTransactionsResponse, error) {
|
||||
func (tc *TransactionClient) List(ctx context.Context) (*models.ListTransactionsResponse, error) {
|
||||
var resp models.ListTransactionsResponse
|
||||
path := "/api/v1/transaction/"
|
||||
err := tc.client.Get(path, &resp)
|
||||
err := tc.client.Get(ctx, path, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user