miniflux/internal/reader/atom/parser.go

33 lines
800 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 atom // import "miniflux.app/v2/internal/reader/atom"
2017-11-20 06:10:04 +01:00
import (
"fmt"
2017-11-20 06:10:04 +01:00
"io"
"miniflux.app/v2/internal/model"
xml_decoder "miniflux.app/v2/internal/reader/xml"
2017-11-20 06:10:04 +01:00
)
2019-12-23 07:18:21 +01:00
type atomFeed interface {
Transform(baseURL string) *model.Feed
2019-12-23 07:18:21 +01:00
}
2017-11-21 03:34:11 +01:00
// Parse returns a normalized feed struct from a Atom feed.
func Parse(baseURL string, r io.ReadSeeker, version string) (*model.Feed, error) {
2019-12-23 07:18:21 +01:00
var rawFeed atomFeed
if version == "0.3" {
2019-12-23 07:18:21 +01:00
rawFeed = new(atom03Feed)
} else {
rawFeed = new(atom10Feed)
}
if err := xml_decoder.NewXMLDecoder(r).Decode(rawFeed); err != nil {
return nil, fmt.Errorf("atom: unable to parse feed: %w", err)
2017-11-20 06:10:04 +01:00
}
return rawFeed.Transform(baseURL), nil
2019-12-23 07:18:21 +01:00
}