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
28 lines
581 B
Go
28 lines
581 B
Go
package block
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
|
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
|
)
|
|
|
|
type BlockClient struct {
|
|
client *client.Client
|
|
}
|
|
|
|
func NewBlockClient(c *client.Client) *BlockClient {
|
|
return &BlockClient{client: c}
|
|
}
|
|
|
|
func (bc *BlockClient) Get(ctx context.Context, blockID string) (*models.Block, error) {
|
|
var resp models.Block
|
|
path := fmt.Sprintf("/api/v1/block/%s", blockID)
|
|
err := bc.client.Get(ctx, path, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|