parser.go 666 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 // import "miniflux.app/reader/json"
  5. import (
  6. "encoding/json"
  7. "io"
  8. "miniflux.app/errors"
  9. "miniflux.app/model"
  10. )
  11. // Parse returns a normalized feed struct from a JSON feed.
  12. func Parse(baseURL string, data io.Reader) (*model.Feed, *errors.LocalizedError) {
  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: %q", err)
  17. }
  18. return feed.Transform(baseURL), nil
  19. }