parser.go 620 B

123456789101112131415161718192021222324
  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 json
  5. import (
  6. "encoding/json"
  7. "io"
  8. "github.com/miniflux/miniflux/errors"
  9. "github.com/miniflux/miniflux/model"
  10. )
  11. // Parse returns a normalized feed struct from a JON feed.
  12. func Parse(data io.Reader) (*model.Feed, error) {
  13. feed := new(jsonFeed)
  14. decoder := json.NewDecoder(data)
  15. if err := decoder.Decode(&feed); err != nil {
  16. return nil, errors.NewLocalizedError("Unable to parse JSON Feed: %v", err)
  17. }
  18. return feed.Transform(), nil
  19. }