Add func ReadPayloadFromRequest.

This commit is contained in:
Владислав Весельский 2025-02-06 12:17:09 +03:00
parent 3557a84ae0
commit 783a2dedfa
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,9 @@ package push_common
import (
"context"
"encoding/json"
"io"
"net/http"
"strconv"
"strings"
@ -203,3 +206,15 @@ type PushPayload struct {
ImageUrl string `json:"imageUrl"`
TextVariants []*TextVariant `json:"textVariants"`
}
func ReadPayloadFromRequest(request *http.Request, payload *PushPayload) error {
b, err := io.ReadAll(request.Body)
if err != nil {
return err
}
if b == nil {
return errors.New("Can not read text variants. Request body bytes is nil.")
}
return json.Unmarshal(b, payload)
}