From 53dc6a84cc024d69d5db7d22e3b99d1cb56846b6 Mon Sep 17 00:00:00 2001 From: Sinuhe Date: Sat, 3 Mar 2018 15:31:42 -0500 Subject: [PATCH] organization: just create a opds package --- main.go | 12 ++++++------ author_builder.go => opds/author_builder.go | 2 +- opds/doc.go | 3 +++ entry_builder.go => opds/entry_builder.go | 2 +- feed_builder.go => opds/feed_builder.go | 2 +- link_builder.go => opds/link_builder.go | 2 +- text_builder.go => opds/text_builder.go | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) rename author_builder.go => opds/author_builder.go (98%) create mode 100644 opds/doc.go rename entry_builder.go => opds/entry_builder.go (99%) rename feed_builder.go => opds/feed_builder.go (98%) rename link_builder.go => opds/link_builder.go (98%) rename text_builder.go => opds/text_builder.go (97%) diff --git a/main.go b/main.go index 9d55698..da795c7 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ import ( "path/filepath" "time" + "github.com/dubyte/dir2opds/opds" "golang.org/x/tools/blog/atom" ) @@ -96,7 +97,6 @@ func getContent(req *http.Request, dirpath string) (result []byte, err error) { if isAcquisition(dirpath) { acFeed := &acquisitionFeed{&feed, "http://purl.org/dc/terms/", "http://opds-spec.org/2010/catalog"} result, err = xml.MarshalIndent(acFeed, " ", " ") - } else { result, err = xml.MarshalIndent(feed, " ", " ") } @@ -104,23 +104,23 @@ func getContent(req *http.Request, dirpath string) (result []byte, err error) { } func makeFeed(dirpath string, req *http.Request) atom.Feed { - feedBuilder := FeedBuilder. + feedBuilder := opds.FeedBuilder. ID(req.URL.Path). Title("Catalog in " + req.URL.Path). - Author(AuthorBuilder.Name(author).Email(authorEmail).URI(authorURI).Build()). + Author(opds.AuthorBuilder.Name(author).Email(authorEmail).URI(authorURI).Build()). Updated(time.Now()). - AddLink(LinkBuilder.Rel("start").Href("/").Type(navegationType).Build()) + AddLink(opds.LinkBuilder.Rel("start").Href("/").Type(navegationType).Build()) fis, _ := ioutil.ReadDir(dirpath) for _, fi := range fis { linkIsAcquisition := isAcquisition(filepath.Join(dirpath, fi.Name())) feedBuilder = feedBuilder. - AddEntry(EntryBuilder. + AddEntry(opds.EntryBuilder. ID(req.URL.Path + fi.Name()). Title(fi.Name()). Updated(time.Now()). Published(time.Now()). - AddLink(LinkBuilder. + AddLink(opds.LinkBuilder. Rel(getRel(fi.Name(), linkIsAcquisition)). Title(fi.Name()). Href(getHref(req, fi.Name())). diff --git a/author_builder.go b/opds/author_builder.go similarity index 98% rename from author_builder.go rename to opds/author_builder.go index de57373..a997707 100644 --- a/author_builder.go +++ b/opds/author_builder.go @@ -1,4 +1,4 @@ -package main +package opds import ( "github.com/lann/builder" diff --git a/opds/doc.go b/opds/doc.go new file mode 100644 index 0000000..52840d6 --- /dev/null +++ b/opds/doc.go @@ -0,0 +1,3 @@ +// Package opds provides fluent immutable builders that help fill the structures +// that can be marshalled to xml (opds 1.1) +package opds diff --git a/entry_builder.go b/opds/entry_builder.go similarity index 99% rename from entry_builder.go rename to opds/entry_builder.go index ed5d339..4bb3a19 100644 --- a/entry_builder.go +++ b/opds/entry_builder.go @@ -1,4 +1,4 @@ -package main +package opds import ( "time" diff --git a/feed_builder.go b/opds/feed_builder.go similarity index 98% rename from feed_builder.go rename to opds/feed_builder.go index 1b5ae72..5cda5a4 100644 --- a/feed_builder.go +++ b/opds/feed_builder.go @@ -1,4 +1,4 @@ -package main +package opds import ( "time" diff --git a/link_builder.go b/opds/link_builder.go similarity index 98% rename from link_builder.go rename to opds/link_builder.go index d5ea0f0..c448dd6 100644 --- a/link_builder.go +++ b/opds/link_builder.go @@ -1,4 +1,4 @@ -package main +package opds import ( "github.com/lann/builder" diff --git a/text_builder.go b/opds/text_builder.go similarity index 97% rename from text_builder.go rename to opds/text_builder.go index dddd1e6..cd2924e 100644 --- a/text_builder.go +++ b/opds/text_builder.go @@ -1,4 +1,4 @@ -package main +package opds import ( "github.com/lann/builder"