Kadai3 2 sminamot - #43
Open
sminamot wants to merge 2 commits into
Open
Conversation
mizkei
reviewed
Nov 26, 2018
| if err != nil { | ||
| fmt.Fprintln(os.Stderr, err) | ||
| } | ||
| defer fp.Close() |
There was a problem hiding this comment.
deferは実行された時点の構造体などの情報を積んでしまうので、forの中で利用するのは良くない場合があります
deferはfuncのスコープでしか実行されないので、即時関数でforの中身を囲うなどで対処可能です
| fmt.Fprintln(os.Stderr, err) | ||
| } | ||
| defer fp.Close() | ||
| io.Copy(fh, fp) |
|
|
||
| req, err := http.NewRequest("GET", t, nil) | ||
| tr := &http.Transport{} | ||
| client := &http.Client{Transport: tr} |
There was a problem hiding this comment.
http.Clientはsafe for concurrentですので、どこかで一つつくっておくだけでも十分です
また、Transportはnilであった場合、DefaultTransportが利用されるので、 client := new(http.Client) だけでも問題なく利用できます
https://golang.org/pkg/net/http/#Client
// Transport specifies the mechanism by which individual // HTTP requests are made. // If nil, DefaultTransport is used. Transport RoundTripper
https://github.com/gopherdojo/dojo4/pull/43/files#diff-721da0c5f369336fd01ab4ac84891ea0R144
上記でCancelRequestを呼ぶために生成しているのかもしれませんが、すでにdeprecatedですので、WithContextを利用したほうが良いです
https://golang.org/pkg/net/http/#Transport.CancelRequest
Deprecated: Use Request.WithContext to create a request with a cancelable context instead.
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.
分割ダウンロードを行う