mirror of
https://salsa.debian.org/mdosch/feed-to-muc.git
synced 2024-11-13 01:36:49 +01:00
29 lines
483 B
Go
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
|
|
}
|