organization: just create a opds package

This commit is contained in:
Sinuhe 2018-03-03 15:31:42 -05:00
parent 8e62288b0b
commit 53dc6a84cc
7 changed files with 14 additions and 11 deletions

12
main.go
View File

@ -30,6 +30,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
"github.com/dubyte/dir2opds/opds"
"golang.org/x/tools/blog/atom" "golang.org/x/tools/blog/atom"
) )
@ -96,7 +97,6 @@ func getContent(req *http.Request, dirpath string) (result []byte, err error) {
if isAcquisition(dirpath) { if isAcquisition(dirpath) {
acFeed := &acquisitionFeed{&feed, "http://purl.org/dc/terms/", "http://opds-spec.org/2010/catalog"} acFeed := &acquisitionFeed{&feed, "http://purl.org/dc/terms/", "http://opds-spec.org/2010/catalog"}
result, err = xml.MarshalIndent(acFeed, " ", " ") result, err = xml.MarshalIndent(acFeed, " ", " ")
} else { } else {
result, err = xml.MarshalIndent(feed, " ", " ") 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 { func makeFeed(dirpath string, req *http.Request) atom.Feed {
feedBuilder := FeedBuilder. feedBuilder := opds.FeedBuilder.
ID(req.URL.Path). ID(req.URL.Path).
Title("Catalog in " + 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()). Updated(time.Now()).
AddLink(LinkBuilder.Rel("start").Href("/").Type(navegationType).Build()) AddLink(opds.LinkBuilder.Rel("start").Href("/").Type(navegationType).Build())
fis, _ := ioutil.ReadDir(dirpath) fis, _ := ioutil.ReadDir(dirpath)
for _, fi := range fis { for _, fi := range fis {
linkIsAcquisition := isAcquisition(filepath.Join(dirpath, fi.Name())) linkIsAcquisition := isAcquisition(filepath.Join(dirpath, fi.Name()))
feedBuilder = feedBuilder. feedBuilder = feedBuilder.
AddEntry(EntryBuilder. AddEntry(opds.EntryBuilder.
ID(req.URL.Path + fi.Name()). ID(req.URL.Path + fi.Name()).
Title(fi.Name()). Title(fi.Name()).
Updated(time.Now()). Updated(time.Now()).
Published(time.Now()). Published(time.Now()).
AddLink(LinkBuilder. AddLink(opds.LinkBuilder.
Rel(getRel(fi.Name(), linkIsAcquisition)). Rel(getRel(fi.Name(), linkIsAcquisition)).
Title(fi.Name()). Title(fi.Name()).
Href(getHref(req, fi.Name())). Href(getHref(req, fi.Name())).

View File

@ -1,4 +1,4 @@
package main package opds
import ( import (
"github.com/lann/builder" "github.com/lann/builder"

3
opds/doc.go Normal file
View File

@ -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

View File

@ -1,4 +1,4 @@
package main package opds
import ( import (
"time" "time"

View File

@ -1,4 +1,4 @@
package main package opds
import ( import (
"time" "time"

View File

@ -1,4 +1,4 @@
package main package opds
import ( import (
"github.com/lann/builder" "github.com/lann/builder"

View File

@ -1,4 +1,4 @@
package main package opds
import ( import (
"github.com/lann/builder" "github.com/lann/builder"