-
Notifications
You must be signed in to change notification settings - Fork 1
/
chunk.go
32 lines (28 loc) · 824 Bytes
/
chunk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package httpchunker
import (
"io"
"net/http"
)
// An httpchunker.Chunk represents the corresponding http.Request
// associated with a particular file chunk to be downloaded.
// The error returned by http.NewRequest() should be included
// in the Err field of this struct.
type Chunk struct {
*http.Request
Err error
}
// Wrapper method for http.NewRequest() that returns
// an httpchunker.Chunk.
func NewChunk(method, url string, body io.Reader) Chunk {
req, err := http.NewRequest(method, url, body)
return Chunk{req, err}
}
// Used to setup the httpchunker.Chunk returned by
// httpchunker.NewChunk(), when the error returned by
// http.NewRequest() is nil.
func (chk Chunk) Setup(setup func(req *http.Request)) Chunk {
if chk.Err == nil {
setup(chk.Request)
}
return chk
}