Changes related with parameters
- Adding host parameter - renaming serveAuthorFeed parameter to author - Adding dir2opds started listening message
This commit is contained in:
parent
bf87aca954
commit
917ffdd122
31
main.go
31
main.go
@ -21,6 +21,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
@ -35,11 +36,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
port,
|
port = flag.String("port", "8080", "The server will listen in this port")
|
||||||
dirRoot,
|
host = flag.String("host", "0.0.0.0", "The server will listen in this host")
|
||||||
author,
|
dirRoot = flag.String("dir", "./books", "A directory with books")
|
||||||
authorURI,
|
author = flag.String("author", "", "The server Feed author")
|
||||||
authorEmail string
|
authorURI = flag.String("uri", "", "The feed's author uri")
|
||||||
|
authorEmail = flag.String("email", "", "The feed's author email")
|
||||||
)
|
)
|
||||||
|
|
||||||
const acquisitionType = "application/atom+xml;profile=opds-catalog;kind=acquisition"
|
const acquisitionType = "application/atom+xml;profile=opds-catalog;kind=acquisition"
|
||||||
@ -58,20 +60,23 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&port, "port", "8080", "The server will listen in this port")
|
|
||||||
flag.StringVar(&dirRoot, "dir", "./books", "A directory with books")
|
|
||||||
flag.StringVar(&author, "serveFeedauthor", "", "The feed's author")
|
|
||||||
flag.StringVar(&authorURI, "uri", "", "The feed's author uri")
|
|
||||||
flag.StringVar(&authorEmail, "email", "", "The feed's author email")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
fmt.Println(startValues())
|
||||||
|
|
||||||
http.HandleFunc("/", errorHandler(handler))
|
http.HandleFunc("/", errorHandler(handler))
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
log.Fatal(http.ListenAndServe(*host+":"+*port, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func startValues() string {
|
||||||
|
var result string
|
||||||
|
result = fmt.Sprintf("dir2opds started to listen in: %s:%s", *host, *port)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, req *http.Request) error {
|
func handler(w http.ResponseWriter, req *http.Request) error {
|
||||||
fpath := filepath.Join(dirRoot, req.URL.Path)
|
fpath := filepath.Join(*dirRoot, req.URL.Path)
|
||||||
|
|
||||||
fi, err := os.Stat(fpath)
|
fi, err := os.Stat(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -107,7 +112,7 @@ func makeFeed(dirpath string, req *http.Request) atom.Feed {
|
|||||||
feedBuilder := opds.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(opds.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(opds.LinkBuilder.Rel("start").Href("/").Type(navegationType).Build())
|
AddLink(opds.LinkBuilder.Rel("start").Href("/").Type(navegationType).Build())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user