mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
- Move the seeking inside of DetectFeedFormat instead of having it everywhere in ParseFeed - Provide a hint for the compiler to eliminate a useless bound check in DetectJSONFormat, otherwise it'll check that buffer[i] is valid on every iteration of the loop. This shouldn't make a big difference, but oh well.
34 lines
953 B
Go
34 lines
953 B
Go
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package parser // import "miniflux.app/v2/internal/reader/parser"
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
"miniflux.app/v2/internal/reader/atom"
|
|
"miniflux.app/v2/internal/reader/json"
|
|
"miniflux.app/v2/internal/reader/rdf"
|
|
"miniflux.app/v2/internal/reader/rss"
|
|
)
|
|
|
|
var ErrFeedFormatNotDetected = errors.New("parser: unable to detect feed format")
|
|
|
|
// ParseFeed analyzes the input data and returns a normalized feed object.
|
|
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
|
format, version := DetectFeedFormat(r)
|
|
switch format {
|
|
case FormatAtom:
|
|
return atom.Parse(baseURL, r, version)
|
|
case FormatRSS:
|
|
return rss.Parse(baseURL, r)
|
|
case FormatJSON:
|
|
return json.Parse(baseURL, r)
|
|
case FormatRDF:
|
|
return rdf.Parse(baseURL, r)
|
|
default:
|
|
return nil, ErrFeedFormatNotDetected
|
|
}
|
|
}
|