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:
2025-12-29 11:00:13 -05:00
parent 5576cced09
commit eb6100b736
8 changed files with 140 additions and 64 deletions

View File

@@ -1,6 +1,7 @@
package transactiontype
import (
"context"
"fmt"
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
@@ -15,38 +16,38 @@ func NewTransactionTypeClient(c *client.Client) *TransactionTypeClient {
return &TransactionTypeClient{client: c}
}
func (ttc *TransactionTypeClient) Create(req *models.TransactionTypeCreateRequest) (*models.TransactionTypeCreateResponse, error) {
func (ttc *TransactionTypeClient) Create(ctx context.Context, req *models.TransactionTypeCreateRequest) (*models.TransactionTypeCreateResponse, error) {
var resp models.TransactionTypeCreateResponse
err := ttc.client.Post("/api/v1/transaction-type", models.ContentTypeJSON, req, &resp)
err := ttc.client.Post(ctx, "/api/v1/transaction-type", models.ContentTypeJSON, req, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) Get(txnType string) (*models.TransactionType, error) {
func (ttc *TransactionTypeClient) Get(ctx context.Context, txnType string) (*models.TransactionType, error) {
var resp models.TransactionType
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
err := ttc.client.Get(path, &resp)
err := ttc.client.Get(ctx, path, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) List() (*models.TransactionListResponse, error) {
func (ttc *TransactionTypeClient) List(ctx context.Context) (*models.TransactionListResponse, error) {
var resp models.TransactionListResponse
err := ttc.client.Get("/api/v1/transaction-types", &resp)
err := ttc.client.Get(ctx, "/api/v1/transaction-types", &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) Delete(txnType string) (*models.SuccessResponse, error) {
func (ttc *TransactionTypeClient) Delete(ctx context.Context, txnType string) (*models.SuccessResponse, error) {
var resp models.SuccessResponse
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
err := ttc.client.Delete(path, &resp)
err := ttc.client.Delete(ctx, path, &resp)
if err != nil {
return nil, err
}