-
Notifications
You must be signed in to change notification settings - Fork 1
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
Микросервисы #26
base: main
Are you sure you want to change the base?
Микросервисы #26
Conversation
# Conflicts: # cmd/2024_1_ResCogitans/main.go # go.mod # go.sum # internal/delivery/handlers/authorization/auth_handler_test.go # internal/delivery/initialization/use_case_init.go # internal/storage/postgres/user/user_storage.go # internal/usecase/session_usecase.go
cmd/2024_1_ResCogitans/main.go
Outdated
@@ -32,14 +21,24 @@ func main() { | |||
} | |||
logger.Info("Start config") | |||
|
|||
conn, err := grpc.Dial("localhost:8081", grpc.WithTransportCredentials(insecure.NewCredentials())) | |||
if err != nil { | |||
log.Fatalf("did not connect: %v", 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.
Почему тут fatal, а не error? И почему используется пакет lag, а не наш логгер?
cmd/2024_1_ResCogitans/main.go
Outdated
@@ -32,14 +21,24 @@ func main() { | |||
} | |||
logger.Info("Start config") | |||
|
|||
conn, err := grpc.Dial("localhost:8081", grpc.WithTransportCredentials(insecure.NewCredentials())) |
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.
Давай в конфиг вынесем адрес
pdb, rdb, cdb, err := initialization.DataBaseInitialization() | ||
if err != nil { | ||
logger.Error("DataBase initialization error", "error", err) | ||
return |
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.
А почему тут решил убрать return? Мы же не можем работать без БД.
cmd/2024_1_ResCogitans/main.go
Outdated
} | ||
|
||
storages := initialization.StorageInit(pdb, rdb, cdb) | ||
usecases := initialization.UseCaseInit(storages) | ||
usecases := initialization.UseCaseInit(storages, conn) |
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.
Давай клиент полностью проиннициализируем в main
cmd/2024_1_ResCogitans/main.go
Outdated
pdb, rdb, cdb, err := initialization.DataBaseInitialization() | ||
if err != nil { | ||
logger.Error("DataBase initialization error", "error", err) | ||
return | ||
} | ||
|
||
storages := initialization.StorageInit(pdb, rdb, cdb) |
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.
Вообще ни из имени метода ни из имени переменной не понятно, что это за сторадж. Код должен быть самодокументируемым.
internal/service/proto/session.proto
Outdated
|
||
message GetSessionResponse { | ||
int32 userID = 1; | ||
string error = 2; |
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.
Обычно если что-то идет не так ошибку возвращают средствами протокола
internal/service/proto/session.proto
Outdated
@@ -0,0 +1,37 @@ | |||
syntax = "proto3"; |
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.
Т.к. у нас несколько сервисов в одном репозитории, предлагаю вынести код каждого сервиса в отдельную директорию. Внутри директории оставляем структуру описанную в project-layout. proto файлы следует размещать в /api.
return &SessionUseCase{ | ||
SessionStorage: storage, | ||
client: gen.NewSessionServiceClient(conn), |
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.
Давай клиента создавать в main функции
internal/usecase/session_usecase.go
Outdated
if response.Error != "" { | ||
return errors.New(response.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.
Чуть выше писал - давай ошибки получать средствами протокола. Т.е. тут все ошибки должны проверяться через err
func NewSessionStorage(client *redis.Client) *RedisStorage { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
// Обеспечение освобождения ресурсов контекста при завершении работы | ||
go func() { | ||
<-ctx.Done() | ||
cancel() | ||
}() | ||
return &RedisStorage{ | ||
client: client, | ||
ctx: ctx, | ||
mu: sync.Mutex{}, | ||
} |
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.
Вроде обсуждали что тут нужно поправить
…е в env файл, доработка взаимодействия с микросервисом
…ого общего логгера во всех частях сервера, избавление от устаревших функций
No description provided.