Skip to content

Iter25#24

Merged
ryabkov82 merged 8 commits into
mainfrom
iter25
Aug 4, 2025
Merged

Iter25#24
ryabkov82 merged 8 commits into
mainfrom
iter25

Conversation

@ryabkov82

Copy link
Copy Markdown
Owner

No description provided.

Comment thread api/shortener.proto
@@ -0,0 +1,80 @@
syntax = "proto3";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На курсе не разбирался OpaqueAPI: https://go.dev/blog/protobuf-opaque. Сейчас это де-факто стандарт для gRPC, потому если будет возможность, то постарайся мигрировать свой код на OpaqueAPI. Если времени не хватит, то попробуй разобраться зачем он нужен и подумай о том, чтобы исползовать его в выпускном проекте.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Насколько я понимаю у меня уже используется OpaqueAPI (также известный как google.golang.org/protobuf или "APIv2")
syntax = "proto3"; в .proto-файле — это корректно, это просто версия синтаксиса (не путать с версией библиотеки для Go).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpaqueAPI предполагает получение доступа к полям proto-запросов при помощи геттеров, в частности. Сейчас у тебя это не так. Посмотри на гайд по миграции на OpaqueAPI

Comment thread internal/app/config/config.go Outdated

// Проверка порта
portNum, err := strconv.Atoi(port)
if err != nil || portNum < 1 || portNum > 65535 {

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://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

minPortIndex лучше выбрать равным 49152

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Исправил

Comment thread internal/app/config/config.go Outdated
// Проверка порта
portNum, err := strconv.Atoi(port)
if err != nil || portNum < 1 || portNum > 65535 {
return errors.New("port must be between 1 and 65535")

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
Owner Author

Choose a reason for hiding this comment

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

Исправил

Comment thread internal/app/config/config.go Outdated

if envGRPCAddr := os.Getenv("GRPC_SERVER_ADDRESS"); envGRPCAddr != "" {
if err := validateGRPCServerAddr(envGRPCAddr); err != nil {
log.Fatalf("invalid GRPC_SERVER_ADDRESS: %v", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

log.Fatal завершает процесс с ненулевым кодом завершения (что указывает на то, что процесс завершился с ошибкой). Не стоит делать это из глубины кода: лучше прокинуть ошибку наверх, т.к. возможно наверху мы сможем ее обработать. Если подходящего обработчика нет, то ошибка должна дойти до точки входа, спровоцировать graceful shutdown приложения и, после, завершение процесса.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Исправил


err := issueNewToken(ctx, jwtKey)
if err != nil {
return nil, status.Error(codes.Internal, "failed to generate token")

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
Owner Author

Choose a reason for hiding this comment

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

Исправил

Comment thread test/testutils/grpc_client.go Outdated
select {
case <-connectionReady:
// Соединение готово к работе
fmt.Println("Connection established successfully")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Для логирования используй логгер, а не fmt

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Исправил

Comment thread test/testutils/grpc_client.go Outdated
// Соединение готово к работе
fmt.Println("Connection established successfully")
case <-ctx.Done():
panic("connection timeout exceeded: server not responding")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не надо паниковать из глубины кода, старайся всегда производить graceful shutdown

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Исправил

Sergey.Ryabkov added 2 commits July 31, 2025 18:09
@ryabkov82 ryabkov82 merged commit 85062b5 into main Aug 4, 2025
3 checks passed
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