miniflux/internal/reader/json/parser.go

23 lines
605 B
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-11-20 06:10:04 +01:00
package json // import "miniflux.app/v2/internal/reader/json"
2017-11-20 06:10:04 +01:00
import (
"encoding/json"
"fmt"
2017-11-20 06:10:04 +01:00
"io"
"miniflux.app/v2/internal/model"
2017-11-20 06:10:04 +01:00
)
2021-04-03 04:00:06 +02:00
// Parse returns a normalized feed struct from a JSON feed.
func Parse(baseURL string, data io.Reader) (*model.Feed, error) {
jsonFeed := new(JSONFeed)
if err := json.NewDecoder(data).Decode(&jsonFeed); err != nil {
return nil, fmt.Errorf("json: unable to parse feed: %w", err)
2017-11-20 06:10:04 +01:00
}
return NewJSONAdapter(jsonFeed).BuildFeed(baseURL), nil
2017-11-20 06:10:04 +01:00
}