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:
49
README.md
49
README.md
@@ -14,8 +14,10 @@ go get git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go"
|
||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
||||
@@ -30,13 +32,17 @@ func main() {
|
||||
"https://your-dragonchain-endpoint.com",
|
||||
)
|
||||
|
||||
// Create a context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Check system health
|
||||
if err := client.System.Health(); err != nil {
|
||||
if err := client.System.Health(ctx); err != nil {
|
||||
log.Fatal("Health check failed:", err)
|
||||
}
|
||||
|
||||
// Get system status
|
||||
status, err := client.System.Status()
|
||||
status, err := client.System.Status(ctx)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to get status:", err)
|
||||
}
|
||||
@@ -51,7 +57,7 @@ func main() {
|
||||
Tag: "example-tag",
|
||||
}
|
||||
|
||||
resp, err := client.Transaction.Create(txn)
|
||||
resp, err := client.Transaction.Create(ctx, txn)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to create transaction:", err)
|
||||
}
|
||||
@@ -61,31 +67,34 @@ func main() {
|
||||
|
||||
## Available Endpoints
|
||||
|
||||
All API methods accept a `context.Context` as their first parameter for timeout and cancellation control.
|
||||
|
||||
### System
|
||||
- `Health()` - Check system health
|
||||
- `Status()` - Get system status
|
||||
- `Health(ctx)` - Check system health
|
||||
- `Status(ctx)` - Get system status
|
||||
|
||||
### Transaction
|
||||
- `Create(req)` - Create a new transaction
|
||||
- `CreateBulk(req)` - Create multiple transactions
|
||||
- `Get(transactionID)` - Get transaction by ID
|
||||
- `Create(ctx, req)` - Create a new transaction
|
||||
- `CreateBulk(ctx, req)` - Create multiple transactions
|
||||
- `Get(ctx, transactionID)` - Get transaction by ID
|
||||
- `List(ctx)` - List all transactions
|
||||
|
||||
### Transaction Type
|
||||
- `Create(req)` - Create a new transaction type
|
||||
- `Get(txnType)` - Get transaction type by name
|
||||
- `List()` - List all transaction types
|
||||
- `Delete(txnType)` - Delete a transaction type
|
||||
- `Create(ctx, req)` - Create a new transaction type
|
||||
- `Get(ctx, txnType)` - Get transaction type by name
|
||||
- `List(ctx)` - List all transaction types
|
||||
- `Delete(ctx, txnType)` - Delete a transaction type
|
||||
|
||||
### Smart Contract
|
||||
- `Create(req)` - Create a new smart contract
|
||||
- `Get(contractID)` - Get smart contract by ID
|
||||
- `List()` - List all smart contracts
|
||||
- `Update(contractID, req)` - Update a smart contract
|
||||
- `Upload(contractID, req)` - Upload smart contract code
|
||||
- `Delete(contractID)` - Delete a smart contract
|
||||
- `Create(ctx, req)` - Create a new smart contract
|
||||
- `Get(ctx, contractID)` - Get smart contract by ID
|
||||
- `List(ctx)` - List all smart contracts
|
||||
- `Update(ctx, contractID, req)` - Update a smart contract
|
||||
- `Upload(ctx, contractID, filepath)` - Upload smart contract code
|
||||
- `Delete(ctx, contractID)` - Delete a smart contract
|
||||
|
||||
### Block
|
||||
- `Get(blockID)` - Get block by ID
|
||||
- `Get(ctx, blockID)` - Get block by ID
|
||||
|
||||
## Authentication
|
||||
|
||||
@@ -93,4 +102,4 @@ The SDK uses HMAC-SHA256 authentication. You need to provide:
|
||||
- `publicID` - Your Dragonchain public ID
|
||||
- `authKeyID` - Your authentication key ID
|
||||
- `authKey` - Your authentication key
|
||||
- `baseURL` - The base URL of your Dragonchain node (e.g., "https://mychain.dragonchain.com")
|
||||
- `baseURL` - The base URL of your Dragonchain node (e.g., "https://chains.dragonchain.com")
|
||||
Reference in New Issue
Block a user