-
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
Open
AlGrItm
wants to merge
9
commits into
main
Choose a base branch
from
services
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Микросервисы #26
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
01cf1c9
Добавление теста для авторизации
1673367
Микрос
cca21ed
Сырая версия микросервиса сессий
4af9def
Запуск первого микросервиса
bc3e795
Возвращение 400 кода, если пользователь не найден в базе данных
3807f3c
Merge branch 'refs/heads/database' into services
89837ed
Обновление ветки services относительно текущей database
820ec98
Изменение расположения файлов микросервиса, помещение данных о сервер…
f7b5810
Добавление dig package для инициализации, настройка использования одн…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
syntax = "proto3"; | ||
|
||
package session; | ||
|
||
option go_package = "session_service/gen"; | ||
|
||
service SessionService { | ||
rpc CreateSession (SaveSessionRequest) returns (SaveSessionResponse); | ||
rpc GetSession (GetSessionRequest) returns (GetSessionResponse); | ||
rpc DeleteSession (DeleteSessionRequest) returns (DeleteSessionResponse); | ||
} | ||
|
||
message SaveSessionRequest { | ||
int32 userID = 1; | ||
} | ||
|
||
message SaveSessionResponse { | ||
string sessionID = 1; | ||
} | ||
|
||
message GetSessionRequest { | ||
string sessionID = 1; | ||
} | ||
|
||
message GetSessionResponse { | ||
int32 userID = 1; | ||
} | ||
|
||
message DeleteSessionRequest { | ||
string sessionID = 1; | ||
} | ||
|
||
message DeleteSessionResponse { | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/internal/delivery/server" | ||
"go.uber.org/dig" | ||
"golang.org/x/exp/slog" | ||
|
||
"github.com/go-park-mail-ru/2024_1_ResCogitans/internal/config" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/internal/delivery/initialization" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/internal/delivery/server" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/internal/usecase" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/router" | ||
"github.com/go-park-mail-ru/2024_1_ResCogitans/utils/logger" | ||
_ "github.com/swaggo/http-swagger/example/go-chi/docs" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server seller server. | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @contact.name API Support | ||
// @contact.url http://www.swagger.io/support | ||
// @contact.email [email protected] | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
|
||
// @host localhost:8080 | ||
// @BasePath /api/v1 | ||
func main() { | ||
logger := logger.Logger() | ||
container := dig.New() | ||
|
||
cfg, err := config.LoadConfig() | ||
if err != nil { | ||
logger.Error("Failed to load config", "error", err) | ||
return | ||
log.Fatalf("Failed to load config: %v", err) | ||
} | ||
logger.Info("Start config") | ||
|
||
pdb, rdb, cdb, err := initialization.DataBaseInitialization() | ||
if err != nil { | ||
logger.Error("DataBase initialization error", "error", err) | ||
logg := logger.NewLogger(cfg) | ||
|
||
if err := container.Provide(func() *config.Config { return cfg }); err != nil { | ||
log.Fatalf("Failed to provide config: %v", err) | ||
} | ||
if err := container.Provide(func() *slog.Logger { return logg }); err != nil { | ||
log.Fatalf("Failed to provide logger: %v", err) | ||
} | ||
|
||
if err := registerDependencies(container); err != nil { | ||
logg.Error("Failed to register dependencies", "error", err) | ||
return | ||
} | ||
|
||
storages := initialization.StorageInit(pdb, rdb, cdb) | ||
usecases := initialization.UseCaseInit(storages) | ||
handlers := initialization.HandlerInit(usecases) | ||
err = container.Invoke(func(cfg *config.Config, logger *slog.Logger, r *chi.Mux) { | ||
logger.Info(fmt.Sprintf("Server is listening on %s", cfg.HTTPServer.Address)) | ||
|
||
if err := server.StartServer(r, cfg); err != nil { | ||
logger.Error("Failed to start server", "error", err) | ||
} | ||
}) | ||
if err != nil { | ||
logg.Error("Failed to start application", "error", err) | ||
} | ||
} | ||
|
||
router := router.SetupRouter(cfg, handlers) | ||
func registerDependencies(container *dig.Container) error { | ||
// Создание среза функций-зависимостей, возвращающих ошибку, которая будет в дальнейшем записываться в логи | ||
providers := []func() error{ | ||
func() error { | ||
return container.Provide(func(cfg *config.Config, logger *slog.Logger) (*grpc.ClientConn, error) { | ||
conn, err := grpc.NewClient(fmt.Sprintf("%s:%d", cfg.SessionService.Host, cfg.SessionService.Port), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to connect to gRPC server: %w", err) | ||
} | ||
return conn, nil | ||
}) | ||
}, | ||
func() error { return container.Provide(initialization.DataBaseInitialization) }, | ||
func() error { return container.Provide(initialization.StorageInit) }, | ||
func() error { return container.Provide(usecase.NewSessionUseCase) }, | ||
func() error { return container.Provide(initialization.UseCaseInit) }, | ||
func() error { return container.Provide(initialization.HandlerInit) }, | ||
func() error { return container.Provide(router.SetupRouter) }, | ||
} | ||
|
||
if err := server.StartServer(router, cfg); err != nil { | ||
logger.Error("Failed to start server", "error", err) | ||
return | ||
for _, provider := range providers { | ||
if err := provider(); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.
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.
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? Мы же не можем работать без БД.