Skip to content

Kadai3 akuchii - #41

Open
hakuta wants to merge 6 commits into
gopherdojo:masterfrom
hakuta:kadai3-akuchii
Open

Kadai3 akuchii#41
hakuta wants to merge 6 commits into
gopherdojo:masterfrom
hakuta:kadai3-akuchii

Conversation

@hakuta

@hakuta hakuta commented Nov 25, 2018

Copy link
Copy Markdown

タイピングゲームを作ろう

  • 標準出力に英単語を出す(出すものは自由)
    英単語のリストをcsvやjsonから読み込んだりできるようにしたかったが、ファイル内に書いてしまっている
  • 標準入力から1行受け取る
  • 制限時間内に何問解けたか表示する
    context.WithTimeoutを使って制限時間を実装

分割ダウンロードを行う

  • Rangeアクセスを用いる
  • いくつかのゴルーチンでダウンロードしてマージする
    他の方の実装やgithub.com/Code-Hex/pgetを参考に実装
  • エラー処理を工夫する
  • golang.org/x/sync/errgroupパッケージなどを使ってみる
    errgroupを使ってみたが、errorが起きた時にどうなるのか試せていないです...
  • キャンセルが発生した場合の実装を行う

エラー処理の工夫、キャンセル発生時の実装が未実装ですが一旦提出します。
テストは時間がとれず用意できていません...

@mizkei mizkei left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしましたので、参考にしていただければと思います

Comment thread kadai3-1/akuchii/game/game.go Outdated
}

// NewGame generates new Game instance
func NewGame(w io.Writer, words []string, timeout int) *Game {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout 、利用する側から単位がわからないと何渡せばよいかわからなくなってしまう(秒、分、ミリ秒など)ので、型を time.Duration にするとわかりやすくなったりします

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

利用する側のことを考えて型を考えるのがよいんですね
26d3564

Comment thread kadai3-1/akuchii/game/game.go Outdated
}

func (g *Game) setNewIdx() {
rand.Seed(time.Now().UnixNano())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initでSeedをセットしているので、Seedは毎回呼ばなくても問題ありません

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにそうですね!
c8f07b2

Comment thread kadai3-1/akuchii/game/game.go Outdated
ctx, cancel := context.WithTimeout(ctx, time.Duration(g.timeout)*time.Second)
defer cancel()

ch := input(os.Stdin)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

せっかく inputio.Reader を受け取るようになっているので、NewGameかStartがio.Readerを受け取るようにして、gameパッケージがos.Stdinに依存しないようにするとテストしやすくなると思います

Copy link
Copy Markdown
Author

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)

Copy link
Copy Markdown

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 という定数が存在していますので、それを利用することもできます

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーの可能性もあるので、エラーは捨てない方が良いと思います

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定数あるの知りませんでした。ありがとうございます。
エラー捨てない方がよいですよね
fixed c33add5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants