lab4: исправления по ревью
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -271,15 +270,15 @@ func (h *Handler) CreateMessage(
|
||||
}, nil
|
||||
}
|
||||
|
||||
// messageFingerprint canonicalises the create-message payload so that the key
|
||||
// order of the client JSON cannot change the fingerprint, while a different
|
||||
// payload with the same Idempotency-Key can (contract 1.3.0).
|
||||
// messageFingerprint canonicalises the create-message payload so that JSON key
|
||||
// order cannot change the fingerprint, while a different payload (including a
|
||||
// different attachment order) with the same Idempotency-Key can. Absent
|
||||
// attachment_ids and [] are equivalent, as required by the contract.
|
||||
func messageFingerprint(req *oas.CreateMessage) ([sha256.Size]byte, error) {
|
||||
ids := make([]uuid.UUID, 0, len(req.AttachmentIds))
|
||||
ids = append(ids, req.AttachmentIds...)
|
||||
slices.SortFunc(ids, func(left, right uuid.UUID) int {
|
||||
return bytes.Compare(left[:], right[:])
|
||||
})
|
||||
ids := req.AttachmentIds
|
||||
if ids == nil {
|
||||
ids = []uuid.UUID{}
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(struct {
|
||||
Text string `json:"text"`
|
||||
|
||||
Reference in New Issue
Block a user