Kadai3 akuchii - #41
Open
hakuta wants to merge 6 commits into
Open
Conversation
mizkei
reviewed
Nov 26, 2018
| } | ||
|
|
||
| // NewGame generates new Game instance | ||
| func NewGame(w io.Writer, words []string, timeout int) *Game { |
There was a problem hiding this comment.
timeout 、利用する側から単位がわからないと何渡せばよいかわからなくなってしまう(秒、分、ミリ秒など)ので、型を time.Duration にするとわかりやすくなったりします
| } | ||
|
|
||
| func (g *Game) setNewIdx() { | ||
| rand.Seed(time.Now().UnixNano()) |
There was a problem hiding this comment.
initでSeedをセットしているので、Seedは毎回呼ばなくても問題ありません
| ctx, cancel := context.WithTimeout(ctx, time.Duration(g.timeout)*time.Second) | ||
| defer cancel() | ||
|
|
||
| ch := input(os.Stdin) |
There was a problem hiding this comment.
せっかく input が io.Reader を受け取るようになっているので、NewGameかStartがio.Readerを受け取るようにして、gameパッケージがos.Stdinに依存しないようにするとテストしやすくなると思います
| } | ||
|
|
||
| func (d Downloader) request(r Range) error { | ||
| req, _ := http.NewRequest("GET", d.url, nil) |
There was a problem hiding this comment.
https://golang.org/pkg/net/http/#pkg-constants
http.MethodGet という定数が存在していますので、それを利用することもできます
Author
There was a problem hiding this comment.
定数あるの知りませんでした。ありがとうございます。
エラー捨てない方がよいですよね
fixed c33add5
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.
タイピングゲームを作ろう
英単語のリストをcsvやjsonから読み込んだりできるようにしたかったが、ファイル内に書いてしまっている
context.WithTimeoutを使って制限時間を実装分割ダウンロードを行う
他の方の実装やgithub.com/Code-Hex/pgetを参考に実装
errgroupを使ってみたが、errorが起きた時にどうなるのか試せていないです...エラー処理の工夫、キャンセル発生時の実装が未実装ですが一旦提出します。
テストは時間がとれず用意できていません...