Skip to content

Commit

Permalink
[rget]fix error procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
imura81gt committed Dec 22, 2019
1 parent 1765566 commit 809e8de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion kadai3/imura81gt/rget/cmd/rget/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ func main() {

option.URL = urls[0]
fmt.Println(option)
rget.Run(option)
err := rget.Run(option)
if err != nil {
fmt.Fprintf(os.Stderr, "err: %s", err)
os.Exit(1)
}
}
11 changes: 6 additions & 5 deletions kadai3/imura81gt/rget/rget.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,33 @@ func (u *Unit) Write(data []byte) (int, error) {

type Units []Unit

func Run(option Option) {
func Run(option Option) error {
fmt.Printf("%+v\n", option)
err := option.checkingHeaders()
if err != nil {
fmt.Errorf("%s", err)
return fmt.Errorf("%s", err)
}

option.divide()

tmpDir, err := ioutil.TempDir("", "rget")
if err != nil {
fmt.Errorf("%s", err)
return fmt.Errorf("%s", err)
}
defer os.RemoveAll(tmpDir)
fmt.Println(tmpDir)

err = option.parallelDownload(tmpDir)
if err != nil {
fmt.Errorf("%s", err)
return fmt.Errorf("%s", err)
}

err = option.combine(tmpDir)
if err != nil {
fmt.Errorf("%s", err)
return fmt.Errorf("%s", err)
}

return nil
}

func (o *Option) checkingHeaders() error {
Expand Down

0 comments on commit 809e8de

Please sign in to comment.