@@ -38,32 +38,33 @@ func (u *Unit) Write(data []byte) (int, error) {
38
38
39
39
type Units []Unit
40
40
41
- func Run (option Option ) {
41
+ func Run (option Option ) error {
42
42
fmt .Printf ("%+v\n " , option )
43
43
err := option .checkingHeaders ()
44
44
if err != nil {
45
- fmt .Errorf ("%s" , err )
45
+ return fmt .Errorf ("%s" , err )
46
46
}
47
47
48
48
option .divide ()
49
49
50
50
tmpDir , err := ioutil .TempDir ("" , "rget" )
51
51
if err != nil {
52
- fmt .Errorf ("%s" , err )
52
+ return fmt .Errorf ("%s" , err )
53
53
}
54
54
defer os .RemoveAll (tmpDir )
55
55
fmt .Println (tmpDir )
56
56
57
57
err = option .parallelDownload (tmpDir )
58
58
if err != nil {
59
- fmt .Errorf ("%s" , err )
59
+ return fmt .Errorf ("%s" , err )
60
60
}
61
61
62
62
err = option .combine (tmpDir )
63
63
if err != nil {
64
- fmt .Errorf ("%s" , err )
64
+ return fmt .Errorf ("%s" , err )
65
65
}
66
66
67
+ return nil
67
68
}
68
69
69
70
func (o * Option ) checkingHeaders () error {
@@ -173,6 +174,8 @@ func (o *Option) downloadWithContext(
173
174
req .Header .Set ("Range" , byteRange )
174
175
175
176
client := http .DefaultClient
177
+ // TODO: should check resp.StatusCode.
178
+ // client.Do cannot seems to return the err when statusCode is 50x etc.
176
179
resp , err := client .Do (req )
177
180
if err != nil {
178
181
fmt .Printf ("client err: %s" , err )
0 commit comments