Перенести реализацию lab5 в skeleton lab6

This commit is contained in:
Vladislav Kunetskiy
2026-11-04 15:10:14 +03:00
parent 470d9d6f1e
commit 42629c41ec
419 changed files with 75841 additions and 24 deletions
+44
View File
@@ -0,0 +1,44 @@
package rest
import (
"log/slog"
"net/http"
"mtusi-messenger/internal/transport/rest/internal/oas"
)
func NewRouter(
handler oas.Handler,
security oas.SecurityHandler,
extensions *Extensions,
log *slog.Logger,
maxBodyBytes, maxUploadBytes int64,
) (http.Handler, error) {
server, err := oas.NewServer(
handler,
security,
oas.WithErrorHandler(newErrorHandler(log)),
oas.WithNotFound(newNotFoundHandler(log)),
oas.WithMethodNotAllowed(newMethodNotAllowedHandler(log)),
oas.WithMiddleware(loggingMiddleware(log)),
)
if err != nil {
return nil, err
}
mux := http.NewServeMux()
if extensions != nil {
// These routes are an optional contract extension (presigned uploads).
// They live outside the generated server so contracts/openapi.json stays
// byte-identical to the mandatory contract.
mux.Handle("/api/v1/chats/{chat_id}/attachments/presign", extensions.Presign())
mux.Handle("/api/v1/attachments/{attachment_id}/complete", extensions.Complete())
}
mux.Handle("/", server)
return requestIDMiddleware(
instanceIDMiddleware(InstanceID(), bodyLimitMiddleware(maxBodyBytes, maxUploadBytes, log, mux)),
), nil
}