Skip to content

kadai3-2 shuheiktgw - #49

Open
shuheiktgw wants to merge 3 commits into
gopherdojo:masterfrom
shuheiktgw:kadai3-2-shuheiktgw
Open

kadai3-2 shuheiktgw#49
shuheiktgw wants to merge 3 commits into
gopherdojo:masterfrom
shuheiktgw:kadai3-2-shuheiktgw

Conversation

@shuheiktgw

@shuheiktgw shuheiktgw commented Nov 27, 2018

Copy link
Copy Markdown

遅くなりましたが, 課題3-2を書きました! 🙇

分割ダウンローダを作ろう

  • Rangeアクセスを用いる
  • いくつかのゴルーチンでダウンロードしてマージする
  • golang.org/x/sync/errgourpパッケージなどを使ってみる
  • キャンセルが発生した場合の実装を行う

@shuheiktgw

shuheiktgw commented Nov 27, 2018

Copy link
Copy Markdown
Author

errgroup.WithContextコメント

// The derived Context is canceled the first time a function passed to Go
// returns a non-nil error or the first time Wait returns, whichever occurs
// first.

って書いてあるので WithContext 使えばエラーが各gorutineで返ってきた場合はキャンセルされるという認識なのですがあってるのかな...? キャンセルが発生した場合の実装を行う というのはそういう意味ではない?

@shuheiktgw

Copy link
Copy Markdown
Author

テスト書きたかったけど力付きました 😇

@mizkei mizkei left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしましたので、参考にしていただければと思います

ss := strings.Split(u.Path, "/")
fname := ss[len(ss)-1]

res, err := http.Head(rawURL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Accept-Ranges
この時点で Accept-Ranges をチェックしておいたほうが良いと思います

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに,ありがとうございます!
RangeRequestとNonRangeRequestに分けて扱うようにしました.

Comment thread kadai3-2/shuheiktgw/gget/request.go Outdated

// Do sends a real HTTP requests in parallel
func (r *Request) Do() error {
eg, _ := errgroup.WithContext(context.TODO())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://godoc.org/golang.org/x/sync/errgroup#WithContext

The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.

このcontext.Contextを受け取って、それを利用しないと意味がなくなってしまいます
この場合は http.RequestWithContext を利用して渡すなどの必要があります

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完全に勘違いしてました... 😇
ありがとうございます!

@shuheiktgw

Copy link
Copy Markdown
Author

今更ですが指摘頂いた箇所を修正しました! 🙇

@suaaa7 suaaa7 mentioned this pull request Aug 31, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants