-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/create sever #41
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Mikens404, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes the foundational HTTP server setup for the application, transitioning the project from a placeholder 'Hello world' to a functional server. It integrates core application components by initializing train and reservation services along with their respective repositories. The changes define the main entry point for the application, preparing it to handle incoming requests by properly wiring up all necessary dependencies. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
このプルリクエストは、HTTPサーバーをセットアップするための変更ですね。全体的に、依存関係の注入(DI)が適切に行われており、サーバーの起動ロジックが実装されていることを確認しました。
いくつか改善のための提案があります。
main.goにおいて、init()関数とグローバル変数の使用を避け、main関数内でサーバーのセットアップを完結させることで、よりテストしやすく、見通しの良いコードにするためのリファクタリングを提案します。internal/infrastructure/train_repository.goのレシーバーの型について、一貫性を保つための提案をしています。main.go内の不要なコメントについても指摘しています。
詳細は各コメントをご確認ください。
| func init() { | ||
| s, err := BuildServer() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| server = s | ||
| } | ||
|
|
||
| func main() { | ||
| fmt.Print("Hello world!") | ||
| slog.Info("hello.") | ||
| if err := http.ListenAndServe(":8080", server); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } |
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()関数とグローバル変数 server を使ってサーバーを初期化する実装になっていますが、この方法はテストのしにくさや、グローバルな状態がコードの可読性を下げる原因となる可能性があります。
main関数内でサーバーのビルドから起動までを完結させることをお勧めします。
- 13行目のグローバル変数
var server http.Handlerを削除します。 - 以下の提案のように
init()関数を削除し、main()関数を修正します。
これにより、main関数がプログラムのエントリーポイントとして全ての初期化ロジックを管理するようになり、コードの流れが追いやすくなります。
func main() {
slog.Info("Starting server...")
server, err := BuildServer()
if err != nil {
log.Fatalf("failed to build server: %v", err)
}
slog.Info("Server is listening on :8080")
if err := http.ListenAndServe(":8080", server); err != nil {
log.Fatalf("failed to listen and serve: %v", err)
}
}| } | ||
|
|
||
| func (t *trainRepositoryImpl) FindTrainInfo(ctx context.Context, trainNumber int) (domain.Train, error) { | ||
| func (t trainRepositoryImpl) FindTrainInfo(ctx context.Context, trainNumber int) (domain.Train, error) { |
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.
FindTrainInfoメソッドのレシーバーが値レシーバー (trainRepositoryImpl) に変更されていますね。trainRepositoryImplは空の構造体なので、値レシーバーでも動作します。
しかし、NewTrainRepository関数がポインタ (*trainRepositoryImpl) を返しているため、一貫性の観点からポインタレシーバー (*trainRepositoryImpl) を使用することが推奨されます。将来的にこの構造体にフィールドが追加された場合にも、意図しないコピーを防ぐことができます。
| func (t trainRepositoryImpl) FindTrainInfo(ctx context.Context, trainNumber int) (domain.Train, error) { | |
| func (t *trainRepositoryImpl) FindTrainInfo(ctx context.Context, trainNumber int) (domain.Train, error) { |
| var server http.Handler | ||
|
|
||
| func BuildServer() (*presentation.Server, error) { | ||
| //reservation_epository |
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.
|
間違えてブランチ立てちゃったよ |
close #34