-
Notifications
You must be signed in to change notification settings - Fork 0
Kadai3-2 hioki-daichi #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@hioki-daichi
hioki-daichi
force-pushed
the
kadai3-2-hioki-daichi
branch
from
September 29, 2018 15:30
7d93cd1 to
dbb3b82
Compare
@hioki-daichi
hioki-daichi
changed the title
(削除) [WIP] Kadai3-2 hioki-daichi (削除ここまで)
(追記) Kadai3-2 hioki-daichi (追記ここまで)
Sep 29, 2018
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
課題3-2 分割ダウンロードを行う
その他やったこと
GET /fooで Gopher の画像を返すような Partial Requests に対応したダミーサーバーです。Range: bytes=0-99のようなリクエストヘッダを指定してリクエストすると その範囲の content を 206 Partial Content とともに返します。-failure-rate-failure-rate=5を指定して実行すると、5% の確率で Internal Server Error を返すようになります。デフォルトは 0% です。max-delay-max-delay=100msを指定して実行すると、0~100ms 遅延させてレスポンスを返すようになります。デフォルトは 1 秒のため、0 から 1 秒の間でランダムに遅延します。port-p-o"index.html"になります。wget と同じ挙動です。-tcontext.WithTimeoutを使いたかったため、指定できるようにしました。デフォルトは 30 秒です。dojo3/kadai3-2/hioki-daichi/termination/termination.go
Lines 15 to 42 in dbb3b82
dojo3/kadai3-2/hioki-daichi/downloading/downloading.go
Lines 64 to 70 in dbb3b82
DEMO
※(注記) 上側では
$ ./bin/dummy_server.go -port=8080 -max-delay=500ms -failure-rate=1のようにしてダミーサーバーを実行しています。(レスポンス時に 0~500ms 遅延させ、1 %の確率で 500 エラーを返すようなオプション)※(注記) 下側では
$ go run main.go -p=32 -t=10s -o=bar.png http://localhost:8080/foo.png; open bar.pngのようにしてコマンドを実行し、作成されたファイルを開いています。(32 並列でタイムアウトは 10 秒、出力先はbar.pngというオプション)demo
補足
curl -s https://raw.githubusercontent.com/gopherdojo/dojo3/kadai3-2-hioki-daichi/kadai3-2/hioki-daichi/coverage.html -o /tmp/coverage-hioki-daichi.html && open /tmp/coverage-hioki-daichi.html所感
Gopher道場#3終わってしばらく経ってしまいましたが、やっと満足行くものが出せました 😌
Ctrl+C 実行時は
context.WithCancelを使い、-t=30sのようなタイムアウトオプション指定時はcontext.WithTimeoutを、リクエストの際は都度req = req.WithContext(ctx)し、errgroup もeg, ctx := errgroup.WithContext(ctx)で context に包み、eg.Goに渡す関数内ではselect { case<-ctx.Done():で待ち受けるなど、 context をたくさん使ったことで context に慣れたような気がします。