feat: add HAproxy and 2 api instances

This commit is contained in:
TAskMAster339
2026-10-10 13:20:58 +03:00
parent a856733fe9
commit 771951cad7
23 changed files with 742 additions and 213 deletions
+16 -2
View File
@@ -1,6 +1,7 @@
package handlers
import (
"encoding/json"
"net/http"
"strings"
@@ -9,7 +10,8 @@ import (
)
type createMessageRequest struct {
Text string `json:"text"`
Text string `json:"text"`
AttachmentIDs json.RawMessage `json:"attachment_ids"`
}
func messageChatID(path string) (string, bool) {
@@ -60,7 +62,19 @@ func createMessageHandler(chats *services.ChatService, messages *services.Messag
writeError(w, 400, "invalid_request", "invalid JSON body", requestID)
return
}
message, err := messages.Create(r.Context(), userID, chat, request.Text)
if len(request.AttachmentIDs) > 0 {
var ids []string
if err := json.Unmarshal(request.AttachmentIDs, &ids); err != nil || ids == nil || len(ids) != 0 {
writeError(w, 400, "invalid_request", "attachments are not supported in lab3; use an empty array or omit attachment_ids", requestID)
return
}
}
keys := r.Header.Values("Idempotency-Key")
if len(keys) != 1 {
writeError(w, 400, "invalid_request", "exactly one Idempotency-Key is required", requestID)
return
}
message, err := messages.CreateIdempotent(r.Context(), userID, chat, request.Text, keys[0])
if err != nil {
writeServiceError(w, err, requestID)
return