Kadai3-2: lfcd85 - #33
Open
lfcd85 wants to merge 23 commits into
Open
Conversation
tenntenn
reviewed
Jun 21, 2019
| PHONY: fmt | ||
| fmt: | ||
| go fmt ./... | ||
| go vet ./... |
tenntenn
reviewed
Jun 21, 2019
| } | ||
|
|
||
| // Execute do the split download. | ||
| func (d *Downloader) Execute() error { |
Member
There was a problem hiding this comment.
せっかくなので引数にcontext.Contextとって、nilならBackgroundにしても良いかも。
tenntenn
reviewed
Jun 21, 2019
| ctx, cancel := context.WithCancel(bc) | ||
| defer cancel() | ||
|
|
||
| req, err := http.NewRequest("GET", d.url.String(), nil) |
tenntenn
reviewed
Jun 21, 2019
| return err | ||
| } | ||
|
|
||
| resp, err := http.DefaultClient.Do(req) |
Member
There was a problem hiding this comment.
HTTPクライアントを変更できるようにしておくとよいかも。
最近はあんまり必要ないかもしれないけど、GAEだと特殊なHTTPクライアントを使う必要があったりするので。
tenntenn
reviewed
Jun 21, 2019
| return err | ||
| } | ||
|
|
||
| err = d.combine(tempDir) |
tenntenn
reviewed
Jun 21, 2019
| if err != nil { | ||
| return err | ||
| } | ||
| fmt.Printf("Download completed! saved at: %v\n", d.outputPath) |
tenntenn
reviewed
Jun 21, 2019
| } | ||
| fmt.Printf("Download completed! saved at: %v\n", d.outputPath) | ||
|
|
||
| return err |
tenntenn
reviewed
Jun 21, 2019
| } | ||
|
|
||
| func (d *Downloader) downloadByRanges(ctx context.Context, tempDir string) error { | ||
| var eg errgroup.Group |
Member
There was a problem hiding this comment.
errgourp.WithContextを呼ばないとキャンセルされない
tenntenn
reviewed
Jun 21, 2019
| return err | ||
| } | ||
|
|
||
| partialPath := generatePartialPath(tempDir, i) |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| for i, _ := range d.ranges { | ||
| partialPath := generatePartialPath(tempDir, i) | ||
| partial, err := os.Open(partialPath) |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| w.Header().Set("Content-Length", strconv.Itoa(len(body))) | ||
| w.WriteHeader(http.StatusPartialContent) | ||
| w.Write(body) |
tenntenn
reviewed
Jun 21, 2019
| return ts, func() { ts.Close() } | ||
| } | ||
|
|
||
| func (tsf *testServerFile) testServerHandler(t *testing.T, w http.ResponseWriter, r *http.Request) { |
Member
There was a problem hiding this comment.
せっかくなんで大きなファイルもテストできるようにするとよいかも。
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
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
分割ダウンローダを作ろうの実装です。Specs
TODO
testdataからテストできるようにしました: 0dd26ec(
hioki-daichiさんのこちらを参考にしました)