Доработайте публикацию и сверку вложений по итогам ревью
This commit is contained in:
+20
-10
@@ -39,20 +39,23 @@ type Deps struct {
|
||||
Sessions *redis.Client
|
||||
SessionTTL time.Duration
|
||||
MaxBodyBytes int64
|
||||
// RequestTimeout bounds every API request; zero means the default.
|
||||
RequestTimeout time.Duration
|
||||
InstanceID string
|
||||
// Zero timeouts use the defaults below.
|
||||
RequestTimeout time.Duration
|
||||
BinaryRequestTimeout time.Duration
|
||||
InstanceID string
|
||||
// IdempotencyTTL zero means the contract's 24 hours.
|
||||
IdempotencyTTL time.Duration
|
||||
Blobs attachment.Blobs
|
||||
MaxUploadBytes int64
|
||||
MaxImagePixels int64
|
||||
AttachmentsCfg attachment.Config
|
||||
}
|
||||
|
||||
// defaultRequestTimeout stays below the server's 10s write timeout, so a
|
||||
// defaultRequestTimeout stays below the server's write timeout, so a
|
||||
// request that gives up on a dependency can still write its 503.
|
||||
const defaultRequestTimeout = 5 * time.Second
|
||||
|
||||
// Binary transfers and decoding share this budget, below the 35s socket timeout.
|
||||
const defaultBinaryRequestTimeout = 30 * time.Second
|
||||
|
||||
const defaultIdempotencyTTL = 24 * time.Hour
|
||||
|
||||
func New(d Deps) *App {
|
||||
@@ -61,7 +64,8 @@ func New(d Deps) *App {
|
||||
if keyTTL == 0 {
|
||||
keyTTL = defaultIdempotencyTTL
|
||||
}
|
||||
chats := chat.NewService(chatstore.NewChats(d.DB), chatstore.NewMessages(d.DB), users, keyTTL)
|
||||
chatRepository := chatstore.NewChats(d.DB)
|
||||
chats := chat.NewService(chatRepository, chatstore.NewMessages(d.DB), users, keyTTL)
|
||||
|
||||
engine := httpx.NewEngine(d.Log, d.MaxBodyBytes, d.InstanceID)
|
||||
probes := health.New(
|
||||
@@ -81,9 +85,15 @@ func New(d Deps) *App {
|
||||
auth.NewHandler(sessions).Register(public, protected)
|
||||
user.NewHandler(users).Register(public, protected)
|
||||
chat.NewHandler(chats).Register(protected)
|
||||
attachments := attachment.NewService(attachmentstore.NewAttachments(d.DB, d.Blobs), d.Blobs, d.MaxUploadBytes, d.MaxImagePixels)
|
||||
binary := engine.Group("/api/v1", httpx.Timeout(30*time.Second), auth.RequireSession(sessions))
|
||||
attachment.NewHandler(attachments).Register(protected, binary)
|
||||
attachments := attachment.NewService(
|
||||
attachmentstore.NewAttachments(d.DB), chatRepository, d.Blobs, d.AttachmentsCfg,
|
||||
)
|
||||
binaryTimeout := d.BinaryRequestTimeout
|
||||
if binaryTimeout == 0 {
|
||||
binaryTimeout = defaultBinaryRequestTimeout
|
||||
}
|
||||
binaryProtected := engine.Group("/api/v1", httpx.Timeout(binaryTimeout), auth.RequireSession(sessions))
|
||||
attachment.NewHandler(attachments).Register(protected, binaryProtected)
|
||||
|
||||
return &App{Engine: engine, Health: probes, Chats: chats}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user