1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

refactor: unexport symbols

This commit is contained in:
Julien Voisin 2025-08-08 02:27:04 +02:00 committed by GitHub
parent a4d51b5586
commit 566670cc06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 369 additions and 376 deletions

View file

@ -23,9 +23,9 @@ func (h *Handler) Export(userID int64) (string, error) {
return "", err
}
subscriptions := make(SubcriptionList, 0, len(feeds))
subscriptions := make(subcriptionList, 0, len(feeds))
for _, feed := range feeds {
subscriptions = append(subscriptions, &Subcription{
subscriptions = append(subscriptions, &subcription{
Title: feed.Title,
FeedURL: feed.FeedURL,
SiteURL: feed.SiteURL,
@ -34,12 +34,12 @@ func (h *Handler) Export(userID int64) (string, error) {
})
}
return Serialize(subscriptions), nil
return serialize(subscriptions), nil
}
// Import parses and create feeds from an OPML import.
func (h *Handler) Import(userID int64, data io.Reader) error {
subscriptions, err := Parse(data)
subscriptions, err := parse(data)
if err != nil {
return err
}

View file

@ -16,6 +16,7 @@ type opmlDocument struct {
Outlines opmlOutlineCollection `xml:"body>outline"`
}
// TODO remove as this is only used in the opml package
func NewOPMLDocument() *opmlDocument {
return &opmlDocument{}
}

View file

@ -11,8 +11,8 @@ import (
"miniflux.app/v2/internal/reader/encoding"
)
// Parse reads an OPML file and returns a SubcriptionList.
func Parse(data io.Reader) (SubcriptionList, error) {
// parse reads an OPML file and returns a SubcriptionList.
func parse(data io.Reader) (subcriptionList, error) {
opmlDocument := NewOPMLDocument()
decoder := xml.NewDecoder(data)
decoder.Entity = xml.HTMLEntity
@ -27,10 +27,10 @@ func Parse(data io.Reader) (SubcriptionList, error) {
return getSubscriptionsFromOutlines(opmlDocument.Outlines, ""), nil
}
func getSubscriptionsFromOutlines(outlines opmlOutlineCollection, category string) (subscriptions SubcriptionList) {
func getSubscriptionsFromOutlines(outlines opmlOutlineCollection, category string) (subscriptions subcriptionList) {
for _, outline := range outlines {
if outline.IsSubscription() {
subscriptions = append(subscriptions, &Subcription{
subscriptions = append(subscriptions, &subcription{
Title: outline.GetTitle(),
FeedURL: outline.FeedURL,
SiteURL: outline.GetSiteURL(),

View file

@ -8,6 +8,13 @@ import (
"testing"
)
// equals compare two subscriptions.
func (s subcription) equals(subscription *subcription) bool {
return s.Title == subscription.Title && s.SiteURL == subscription.SiteURL &&
s.FeedURL == subscription.FeedURL && s.CategoryName == subscription.CategoryName &&
s.Description == subscription.Description
}
func TestParseOpmlWithoutCategories(t *testing.T) {
data := `<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
@ -32,10 +39,10 @@ func TestParseOpmlWithoutCategories(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "CNET News.com", FeedURL: "http://news.com.com/2547-1_3-0-5.xml", SiteURL: "http://news.com.com/", Description: "Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media."})
var expected subcriptionList
expected = append(expected, &subcription{Title: "CNET News.com", FeedURL: "http://news.com.com/2547-1_3-0-5.xml", SiteURL: "http://news.com.com/", Description: "Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media."})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -44,7 +51,7 @@ func TestParseOpmlWithoutCategories(t *testing.T) {
t.Fatalf("Wrong number of subscriptions: %d instead of %d", len(subscriptions), 13)
}
if !subscriptions[0].Equals(expected[0]) {
if !subscriptions[0].equals(expected[0]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[0], expected[0])
}
}
@ -67,12 +74,12 @@ func TestParseOpmlWithCategories(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "My Category 1"})
expected = append(expected, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "My Category 1"})
expected = append(expected, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "My Category 2"})
var expected subcriptionList
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "My Category 1"})
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "My Category 1"})
expected = append(expected, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "My Category 2"})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -82,7 +89,7 @@ func TestParseOpmlWithCategories(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -101,11 +108,11 @@ func TestParseOpmlWithEmptyTitleAndEmptySiteURL(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "http://example.org/1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
expected = append(expected, &Subcription{Title: "http://example.org/feed2/", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/feed2/", CategoryName: ""})
var expected subcriptionList
expected = append(expected, &subcription{Title: "http://example.org/1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
expected = append(expected, &subcription{Title: "http://example.org/feed2/", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/feed2/", CategoryName: ""})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -115,7 +122,7 @@ func TestParseOpmlWithEmptyTitleAndEmptySiteURL(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -139,11 +146,11 @@ func TestParseOpmlVersion1(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
expected = append(expected, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Category 2"})
var expected subcriptionList
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Category 2"})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -153,7 +160,7 @@ func TestParseOpmlVersion1(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -173,11 +180,11 @@ func TestParseOpmlVersion1WithoutOuterOutline(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
expected = append(expected, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: ""})
var expected subcriptionList
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: ""})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -187,7 +194,7 @@ func TestParseOpmlVersion1WithoutOuterOutline(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -214,12 +221,12 @@ func TestParseOpmlVersion1WithSeveralNestedOutlines(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Some Category"})
expected = append(expected, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Some Category"})
expected = append(expected, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "Another Category"})
var expected subcriptionList
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Some Category"})
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Some Category"})
expected = append(expected, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "Another Category"})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -229,7 +236,7 @@ func TestParseOpmlVersion1WithSeveralNestedOutlines(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -249,10 +256,10 @@ func TestParseOpmlWithInvalidCharacterEntity(t *testing.T) {
</opml>
`
var expected SubcriptionList
expected = append(expected, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/a&b", SiteURL: "http://example.org/c&d", CategoryName: "Feed 1"})
var expected subcriptionList
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/a&b", SiteURL: "http://example.org/c&d", CategoryName: "Feed 1"})
subscriptions, err := Parse(bytes.NewBufferString(data))
subscriptions, err := parse(bytes.NewBufferString(data))
if err != nil {
t.Fatal(err)
}
@ -262,7 +269,7 @@ func TestParseOpmlWithInvalidCharacterEntity(t *testing.T) {
}
for i := range len(subscriptions) {
if !subscriptions[i].Equals(expected[i]) {
if !subscriptions[i].equals(expected[i]) {
t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
}
}
@ -270,7 +277,7 @@ func TestParseOpmlWithInvalidCharacterEntity(t *testing.T) {
func TestParseInvalidXML(t *testing.T) {
data := `garbage`
_, err := Parse(bytes.NewBufferString(data))
_, err := parse(bytes.NewBufferString(data))
if err == nil {
t.Error("Parse should generate an error")
}

View file

@ -12,8 +12,8 @@ import (
"time"
)
// Serialize returns a SubcriptionList in OPML format.
func Serialize(subscriptions SubcriptionList) string {
// serialize returns a SubcriptionList in OPML format.
func serialize(subscriptions subcriptionList) string {
var b bytes.Buffer
writer := bufio.NewWriter(&b)
writer.WriteString(xml.Header)
@ -31,7 +31,7 @@ func Serialize(subscriptions SubcriptionList) string {
return b.String()
}
func convertSubscriptionsToOPML(subscriptions SubcriptionList) *opmlDocument {
func convertSubscriptionsToOPML(subscriptions subcriptionList) *opmlDocument {
opmlDocument := NewOPMLDocument()
opmlDocument.Version = "2.0"
opmlDocument.Header.Title = "Miniflux"
@ -62,8 +62,8 @@ func convertSubscriptionsToOPML(subscriptions SubcriptionList) *opmlDocument {
return opmlDocument
}
func groupSubscriptionsByFeed(subscriptions SubcriptionList) map[string]SubcriptionList {
groups := make(map[string]SubcriptionList)
func groupSubscriptionsByFeed(subscriptions subcriptionList) map[string]subcriptionList {
groups := make(map[string]subcriptionList)
for _, subscription := range subscriptions {
groups[subscription.CategoryName] = append(groups[subscription.CategoryName], subscription)

View file

@ -9,13 +9,13 @@ import (
)
func TestSerialize(t *testing.T) {
var subscriptions SubcriptionList
subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: "Category 1"})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: "Category 2"})
var subscriptions subcriptionList
subscriptions = append(subscriptions, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
subscriptions = append(subscriptions, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: "Category 1"})
subscriptions = append(subscriptions, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: "Category 2"})
output := Serialize(subscriptions)
feeds, err := Parse(bytes.NewBufferString(output))
output := serialize(subscriptions)
feeds, err := parse(bytes.NewBufferString(output))
if err != nil {
t.Error(err)
}
@ -48,10 +48,10 @@ func TestNormalizedCategoriesOrder(t *testing.T) {
{"Category 1", "Category 3"},
}
var subscriptions SubcriptionList
subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: orderTests[0].naturalOrderName})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: orderTests[1].naturalOrderName})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: orderTests[2].naturalOrderName})
var subscriptions subcriptionList
subscriptions = append(subscriptions, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: orderTests[0].naturalOrderName})
subscriptions = append(subscriptions, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: orderTests[1].naturalOrderName})
subscriptions = append(subscriptions, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: orderTests[2].naturalOrderName})
feeds := convertSubscriptionsToOPML(subscriptions)

View file

@ -3,8 +3,8 @@
package opml // import "miniflux.app/v2/internal/reader/opml"
// Subcription represents a feed that will be imported or exported.
type Subcription struct {
// subcription represents a feed that will be imported or exported.
type subcription struct {
Title string
SiteURL string
FeedURL string
@ -12,12 +12,5 @@ type Subcription struct {
Description string
}
// Equals compare two subscriptions.
func (s Subcription) Equals(subscription *Subcription) bool {
return s.Title == subscription.Title && s.SiteURL == subscription.SiteURL &&
s.FeedURL == subscription.FeedURL && s.CategoryName == subscription.CategoryName &&
s.Description == subscription.Description
}
// SubcriptionList is a list of subscriptions.
type SubcriptionList []*Subcription
// subcriptionList is a list of subscriptions.
type subcriptionList []*subcription