Skip to content
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

Goやってる人にレビューもらったので共有 #12

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

schktjm
Copy link

@schktjm schktjm commented Jul 12, 2020

Goやってる人に質問したらそのままいろいろ編集されちゃったんですが消すのがもったいないので一応共有します!

Copy link
Author

@schktjm schktjm left a comment

Choose a reason for hiding this comment

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

このままだと動かないから共有だけ 🙏

Comment on lines +14 to +20
kenjo, err := ioutil.ReadFile("./utils/" + "kenjo.json")
if err != nil {
panic(err)
}
util := utils.Utils{
Kenjo: kenjo,
}
Copy link
Author

Choose a reason for hiding this comment

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

utils/ 以下のファイルを読み込むはランタイムでやってひらけなかったらパニックしたほうがいいって言われた

Copy link
Author

Choose a reason for hiding this comment

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

リクエストが送られた時にpanicよりはいいとのことです

Copy link
Contributor

Choose a reason for hiding this comment

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

なるほど!

実はここ、jsonファイル読み込みが入るのでビルドしたときに正しく読み込みできるか怪しいかも
今のところDockerfileも実行コンテナにはビルド済みバイナリしか渡してなかったりします

Comment on lines +12 to +15
type Kenjyo struct{
Utils: utils,
}

Copy link
Author

Choose a reason for hiding this comment

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

ランタイムで読み込んだutilsをtypeで渡すのがいいらしい

Copy link
Contributor

Choose a reason for hiding this comment

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

typeってこんな風に使えるのか、知見

Comment on lines +22 to +25
conversionRules, err := utils.JsonDecoder("kenjyo.json")
if err != nil {
return "", err
}
Copy link
Author

Choose a reason for hiding this comment

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

error を握り潰すなとのことです

Copy link
Contributor

Choose a reason for hiding this comment

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

エラー処理サボってたのが発覚してしまう回!😆
申し訳無さ🙏

@@ -1,33 +1,35 @@
package utils
package converter
Copy link
Author

Choose a reason for hiding this comment

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

utils はなんでも入れられるから使わないほうがいいらしい
今回はconvertの処理だけだから converter パッケージにしたほうがいいって

Copy link
Contributor

Choose a reason for hiding this comment

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

たしかに、パッと特定の役割が思い浮かばない命名は避けたほうがいいな
ディレクトリとファイル名も合わせて修正したさ

Comment on lines +6 to +7
"github.com/aizu-go-kapro/keiGo/backend/models"
"github.com/gin-gonic/gin"
Copy link
Author

Choose a reason for hiding this comment

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

パッケージ? のパスの指定の仕方が違うっていわれた

Copy link
Contributor

Choose a reason for hiding this comment

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

Go Modulesのお作法的にGitHub上に上げるパッケージの場合は修正してもらったようなgithub.com/xxx~の形が正しそう

Comment on lines +6 to +7
"github.com/aizu-go-kapro/keiGo/backend/models"
"github.com/gin-gonic/gin"
Copy link
Contributor

Choose a reason for hiding this comment

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

Go Modulesのお作法的にGitHub上に上げるパッケージの場合は修正してもらったようなgithub.com/xxx~の形が正しそう

Comment on lines 10 to 57
const (
Teinei string = "teinei"
Sonkei string = "sonkei"
Kenjyo string = "kenjyo"
teineiKind = "teinei"
sonkeiKind = "sonkei"
kenjyoKind = "kenjyo"
)
// Keigo is controller of keigo
type Keigo struct {
teinei models.Teinei
sonkei models.Sonkei
kenjyo models.Kenjyo
}

// NewKeigo create keigo controller
func NewKeigo() *Keigo {
return &Keigo{}
}

// ConvertKeigo is controller
func (kc *Keigo) ConvertKeigo(c *gin.Context) {
var (
request models.KeigoRequest
response models.KeigoResponse
)

func (kc *KeigoController) ConvertKeigo(c *gin.Context) {
kind := c.Query("kind")
print(kind)
request := models.KeigoRequest{}
response := models.KeigoResponse{}
if kind == "" {
return c.JSON(
http.StatusBadRequest,
map[string]string{"status": "error", "message": "kind is empty"}
// '{"status": "error", "message": "kind is empty"}'
)
}

if err := c.BindJSON(&request); err != nil {
c.Status(http.StatusBadRequest)
} else {
switch kind {
case Teinei:
teinei := models.Teinei{}
response.ConvertedBody = teinei.Convert(request.Body)
case Sonkei:
sonkei := models.Sonkei{}
response.ConvertedBody = sonkei.Convert(request.Body)
case Kenjyo:
kenjyo := models.Kenjyo{}
response.ConvertedBody = kenjyo.Convert(request.Body)
}
c.JSON(http.StatusOK, response)
return c.Status(http.StatusBadRequest)
}

switch kind {
case teineiKind:
response.ConvertedBody = kc.teinei.Convert(request.Body)
case sonkeiKind:
response.ConvertedBody = kc.sonkei.Convert(request.Body)
case kenjyoKind:
response.ConvertedBody = kc.kenjyo.Convert(request.Body)
}

return c.JSON(http.StatusOK, response)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

この辺のうまい書き方わからなかったからとても参考になる!

Comment on lines +14 to +20
kenjo, err := ioutil.ReadFile("./utils/" + "kenjo.json")
if err != nil {
panic(err)
}
util := utils.Utils{
Kenjo: kenjo,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

なるほど!

実はここ、jsonファイル読み込みが入るのでビルドしたときに正しく読み込みできるか怪しいかも
今のところDockerfileも実行コンテナにはビルド済みバイナリしか渡してなかったりします

Comment on lines +22 to +25
kC := controllers.NewKeigo()
api := router.Group("/api/v1")
{
kc := new(controllers.KeigoController)
api.GET("/keigo", kc.ConvertKeigo)
api.GET("/keigo", kC.ConvertKeigo)
Copy link
Contributor

Choose a reason for hiding this comment

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

ここの書き方も参考になります!

Comment on lines +12 to +15
type Kenjyo struct{
Utils: utils,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

typeってこんな風に使えるのか、知見

Comment on lines +22 to +25
conversionRules, err := utils.JsonDecoder("kenjyo.json")
if err != nil {
return "", err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

エラー処理サボってたのが発覚してしまう回!😆
申し訳無さ🙏

@@ -1,33 +1,35 @@
package utils
package converter
Copy link
Contributor

Choose a reason for hiding this comment

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

たしかに、パッと特定の役割が思い浮かばない命名は避けたほうがいいな
ディレクトリとファイル名も合わせて修正したさ

Comment on lines +33 to +34
}
break
Copy link
Contributor

Choose a reason for hiding this comment

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

ここって、。。。みたいに複数記号も想定なので素でbreakすると一文字までしか対応できない挙動になる気がする

@schktjm schktjm marked this pull request as draft July 15, 2020 03:16
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