forked from mtusi2026/mtusi2026lab4
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
"sync/atomic"
|
|
|
|
"messenger/internal/service"
|
|
)
|
|
|
|
type Pinger func(ctx context.Context) error
|
|
|
|
type Handler struct {
|
|
users *service.UserService
|
|
auth *service.AuthService
|
|
chats *service.ChatService
|
|
messages *service.MessageService
|
|
attachments *service.AttachmentService
|
|
deps []Pinger
|
|
log *slog.Logger
|
|
draining atomic.Bool
|
|
}
|
|
|
|
func New(users *service.UserService, auth *service.AuthService, chats *service.ChatService,
|
|
messages *service.MessageService, attachments *service.AttachmentService,
|
|
deps []Pinger, log *slog.Logger) *Handler {
|
|
return &Handler{users: users, auth: auth, chats: chats, messages: messages,
|
|
attachments: attachments, deps: deps, log: log}
|
|
}
|
|
|
|
func (h *Handler) StartDraining() {
|
|
h.draining.Store(true)
|
|
}
|
|
|
|
func (h *Handler) NotFound(w http.ResponseWriter, _ *http.Request) {
|
|
writeError(w, http.StatusNotFound, "not_found", "resource not found")
|
|
}
|
|
|
|
func (h *Handler) MethodNotAllowed(w http.ResponseWriter, _ *http.Request) {
|
|
writeError(w, http.StatusMethodNotAllowed, "invalid_request", "method not allowed")
|
|
}
|