feed-to-muc/vendor/github.com/mmcdole/gofeed/json/parser.go
2020-10-24 12:40:39 +02:00

29 lines
483 B
Go

package json
import (
"bytes"
"io"
jsoniter "github.com/json-iterator/go"
)
var (
j = jsoniter.ConfigCompatibleWithStandardLibrary
)
// Parser is an JSON Feed Parser
type Parser struct{}
// Parse parses an json feed into an json.Feed
func (ap *Parser) Parse(feed io.Reader) (*Feed, error) {
jsonFeed := &Feed{}
buffer := new(bytes.Buffer)
buffer.ReadFrom(feed)
err := j.Unmarshal(buffer.Bytes(), jsonFeed)
if err != nil {
return nil, err
}
return jsonFeed, err
}