Перенести решение лабораторной 1 как основу для лабораторной 2
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// Package app is the composition root: it builds every module with its
|
||||
// in-memory stores and mounts them on one HTTP engine. Both the server
|
||||
// binary and the integration tests start from here.
|
||||
package app
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"messenger/internal/auth"
|
||||
"messenger/internal/chat"
|
||||
chatstore "messenger/internal/chat/store"
|
||||
"messenger/internal/health"
|
||||
"messenger/internal/platform/httpx"
|
||||
"messenger/internal/user"
|
||||
userstore "messenger/internal/user/store"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Engine *gin.Engine
|
||||
Health *health.Handler
|
||||
}
|
||||
|
||||
func New(log *slog.Logger, maxBodyBytes int64) *App {
|
||||
users := user.NewService(userstore.NewInMemUsers())
|
||||
chats := chat.NewService(chatstore.NewInMemChats(), chatstore.NewInMemMessages(), users)
|
||||
|
||||
engine := httpx.NewEngine(log, maxBodyBytes)
|
||||
probes := health.New()
|
||||
probes.Register(engine)
|
||||
|
||||
public := engine.Group("/api/v1")
|
||||
protected := public.Group("", auth.RequireUser(users))
|
||||
user.NewHandler(users).Register(public, protected)
|
||||
chat.NewHandler(chats).Register(protected)
|
||||
|
||||
return &App{Engine: engine, Health: probes}
|
||||
}
|
||||
Reference in New Issue
Block a user