Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии
This commit is contained in:
@@ -144,7 +144,7 @@ func (h *Handler) send(c *gin.Context, actor uuid.UUID) {
|
||||
httpx.Error(c, err)
|
||||
return
|
||||
}
|
||||
message, err := h.chats.Send(c.Request.Context(), actor, chatID, key, req.Text)
|
||||
message, err := h.chats.Send(c.Request.Context(), actor, MessagePayload{ChatID: chatID, IdempotencyKey: key, Text: req.Text})
|
||||
if err != nil {
|
||||
httpx.Error(c, err)
|
||||
return
|
||||
@@ -173,10 +173,7 @@ func (h *Handler) history(c *gin.Context, actor uuid.UUID) {
|
||||
|
||||
var keyPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,128}$`)
|
||||
|
||||
// idempotencyKey reads the Idempotency-Key that names one send attempt. It
|
||||
// is part of this endpoint's input contract, so it is checked here, with
|
||||
// the path and the body, and before access: the answer to a malformed key
|
||||
// is the same for any chat. Two headers are ambiguous and rejected.
|
||||
// idempotencyKey rejects two values of the header as ambiguous.
|
||||
func idempotencyKey(c *gin.Context) (string, error) {
|
||||
values := c.Request.Header.Values("Idempotency-Key")
|
||||
if len(values) != 1 || !keyPattern.MatchString(values[0]) {
|
||||
|
||||
Reference in New Issue
Block a user