Open
Conversation
sryoya
reviewed
Jun 21, 2021
|
|
||
| func (o *omikuji) Draw() { | ||
| if isShogatsu(o.date) { | ||
| o.result = daikichi |
| if isShogatsu(o.date) { | ||
| o.result = daikichi | ||
| } else { | ||
| rand.Seed(time.Now().UnixNano()) |
There was a problem hiding this comment.
rand.Seedみたいな共通の初期化系の処理は、init functionで最初に実行させてしまうという方法があります
| if dateValue != "" { | ||
| date, err := time.Parse(timeForm, dateValue) | ||
| if err != nil { | ||
| log.Fatal(err) |
There was a problem hiding this comment.
この場合、httpのerrorとして返した方が良いと思います。特に、ユーザーが異常な値を入れたら発生する想定内なエラーだと思うので
| handler(w, r) | ||
| rw := w.Result() | ||
| defer rw.Body.Close() | ||
| if rw.StatusCode != http.StatusOK { |
There was a problem hiding this comment.
StatusCodeも期待値に入れると、異常系のテストもできます Bad Requestのときとかも含め
Comment on lines
+22
to
+25
| type omikuji struct { | ||
| result string | ||
| date time.Time | ||
| } |
Comment on lines
+13
to
+16
| daikichi = "大吉" | ||
| ) | ||
|
|
||
| var omikujiResults = []string{"吉", "小吉", "凶"} |
There was a problem hiding this comment.
daikichi以外の値も定数に定義して、daikichiも含めてこのsliceに入れてしまう方が可変性、可読性(一覧性)ともに高いと思います。
| } | ||
|
|
||
| _, month, date := t.Date() | ||
| if month == time.January { |
There was a problem hiding this comment.
ここがfalseの時点で return false すれば、ifをネストしなくてよくなりますね
| ) | ||
|
|
||
| func main() { | ||
| http.HandleFunc("/", handler) |
There was a problem hiding this comment.
これをmain関数の外に置いておくことでhttpのroutingも含めてテストできるようになります
Author
|
@sryoya レビューありがとうございます!別途確認いたします。 |
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.
おみくじ API
お手数ですがレビューお願いいたします。
仕様
利用方法
setup
$ make # テスト & ビルドサーバーの起動
おみくじを引く
ディレクトリ構造
. ├── Makefile ├── README.md ├── go.mod ├── main.go ├── omikuji-server ├── omikuji.go └── omikuji_test.go