payload.go 762 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 ui // import "miniflux.app/ui"
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. "io"
  9. "miniflux.app/model"
  10. )
  11. func decodeEntryStatusPayload(r io.ReadCloser) (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(r)
  18. defer r.Close()
  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. }