Add func ReadPayloadFromRequest.
This commit is contained in:
parent
3557a84ae0
commit
783a2dedfa
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue