payload.go 818 B

123456789101112131415161718192021222324252627282930313233
  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. "io"
  9. "github.com/miniflux/miniflux/model"
  10. )
  11. // DecodeEntryStatusPayload unserialize JSON request to update entry statuses.
  12. func DecodeEntryStatusPayload(data io.Reader) (entryIDs []int64, status string, err error) {
  13. type payload struct {
  14. EntryIDs []int64 `json:"entry_ids"`
  15. Status string `json:"status"`
  16. }
  17. var p payload
  18. decoder := json.NewDecoder(data)
  19. if err = decoder.Decode(&p); err != nil {
  20. return nil, "", fmt.Errorf("invalid JSON payload: %v", err)
  21. }
  22. if err := model.ValidateEntryStatus(p.Status); err != nil {
  23. return nil, "", err
  24. }
  25. return p.EntryIDs, p.Status, nil
  26. }