Skip to content

Commit fc18de8

Browse files
author
postables
authored
Merge pull request #21 from RTradeLtd/dag/put#option
Dag/put#option
2 parents 8b7099f + d6b83d2 commit fc18de8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

options/dag.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type DagPutSettings struct {
55
InputEnc string
66
Kind string
77
Pin string
8+
Hash string
89
}
910

1011
// DagPutOption is a single DagPut option.
@@ -16,6 +17,7 @@ func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
1617
InputEnc: "json",
1718
Kind: "cbor",
1819
Pin: "false",
20+
Hash: "sha2-256",
1921
}
2022

2123
for _, opt := range opts {
@@ -57,3 +59,11 @@ func (dagOpts) Kind(kind string) DagPutOption {
5759
return nil
5860
}
5961
}
62+
63+
// Hash is an option for Dag.Put which specifies the hash function to use
64+
func (dagOpts) Hash(hash string) DagPutOption {
65+
return func(opts *DagPutSettings) error {
66+
opts.Hash = hash
67+
return nil
68+
}
69+
}

request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
type Request struct {
19+
Ctx context.Context
1920
ApiBase string
2021
Command string
2122
Args []string
@@ -33,6 +34,7 @@ func NewRequest(ctx context.Context, url, command string, args ...string) *Reque
3334
"stream-channels": "true",
3435
}
3536
return &Request{
37+
Ctx: ctx,
3638
ApiBase: url + "/api/v0",
3739
Command: command,
3840
Args: args,
@@ -111,7 +113,13 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
111113
if err != nil {
112114
return nil, err
113115
}
116+
117+
req = req.WithContext(r.Ctx)
114118

119+
// Add any headers that were supplied via the RequestBuilder.
120+
for k, v := range r.Headers {
121+
req.Header.Add(k, v)
122+
}
115123
if fr, ok := r.Body.(*files.MultiFileReader); ok {
116124
req.Header.Set("Content-Type", "multipart/form-data; boundary="+fr.Boundary())
117125
req.Header.Set("Content-Disposition", "form-data; name=\"files\"")

0 commit comments

Comments
 (0)