-
Notifications
You must be signed in to change notification settings - Fork 0
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
Kadai3-2 hioki-daichi #50
Open
hioki-daichi
wants to merge
12
commits into
master
Choose a base branch
from
kadai3-2-hioki-daichi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
force-pushed
the
kadai3-2-hioki-daichi
branch
from
September 29, 2018 15:30
7d93cd1
to
dbb3b82
Compare
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.
課題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 と同じ挙動です。-t
context.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
というオプション)補足
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 に慣れたような気がします。