-
Notifications
You must be signed in to change notification settings - Fork 17
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 akuchii #41
base: master
Are you sure you want to change the base?
Kadai3 akuchii #41
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントしましたので、参考にしていただければと思います
kadai3-1/akuchii/game/game.go
Outdated
} | ||
|
||
// NewGame generates new Game instance | ||
func NewGame(w io.Writer, words []string, timeout int) *Game { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout
、利用する側から単位がわからないと何渡せばよいかわからなくなってしまう(秒、分、ミリ秒など)ので、型を time.Duration
にするとわかりやすくなったりします
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
利用する側のことを考えて型を考えるのがよいんですね
26d3564
kadai3-1/akuchii/game/game.go
Outdated
} | ||
|
||
func (g *Game) setNewIdx() { | ||
rand.Seed(time.Now().UnixNano()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initでSeedをセットしているので、Seedは毎回呼ばなくても問題ありません
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかにそうですね!
c8f07b2
kadai3-1/akuchii/game/game.go
Outdated
ctx, cancel := context.WithTimeout(ctx, time.Duration(g.timeout)*time.Second) | ||
defer cancel() | ||
|
||
ch := input(os.Stdin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
せっかく input
が io.Reader
を受け取るようになっているので、NewGameかStartがio.Readerを受け取るようにして、gameパッケージがos.Stdinに依存しないようにするとテストしやすくなると思います
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、たしかにio.Reader
の方がよさそうですね
94a1abd
} | ||
|
||
func (d Downloader) request(r Range) error { | ||
req, _ := http.NewRequest("GET", d.url, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://golang.org/pkg/net/http/#pkg-constants
http.MethodGet
という定数が存在していますので、それを利用することもできます
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エラーの可能性もあるので、エラーは捨てない方が良いと思います
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定数あるの知りませんでした。ありがとうございます。
エラー捨てない方がよいですよね
fixed c33add5
タイピングゲームを作ろう
英単語のリストをcsvやjsonから読み込んだりできるようにしたかったが、ファイル内に書いてしまっている
context.WithTimeout
を使って制限時間を実装分割ダウンロードを行う
他の方の実装やgithub.com/Code-Hex/pgetを参考に実装
errgroup
を使ってみたが、errorが起きた時にどうなるのか試せていないです...エラー処理の工夫、キャンセル発生時の実装が未実装ですが一旦提出します。
テストは時間がとれず用意できていません...