payload.go 739 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package payload
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. "github.com/miniflux/miniflux2/model"
  9. "io"
  10. )
  11. func DecodeEntryStatusPayload(data io.Reader) (entryIDs []int64, status string, err error) {
  12. type payload struct {
  13. EntryIDs []int64 `json:"entry_ids"`
  14. Status string `json:"status"`
  15. }
  16. var p payload
  17. decoder := json.NewDecoder(data)
  18. if err = decoder.Decode(&p); err != nil {
  19. return nil, "", fmt.Errorf("invalid JSON payload: %v", err)
  20. }
  21. if err := model.ValidateEntryStatus(p.Status); err != nil {
  22. return nil, "", err
  23. }
  24. return p.EntryIDs, p.Status, nil
  25. }