we dont need filepath package
This commit is contained in:
parent
4eeea88071
commit
c19afa94a1
16
main.go
16
main.go
@ -26,8 +26,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -80,21 +80,21 @@ func startValues() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 := path.Join(*dirRoot, req.URL.Path)
|
||||||
|
|
||||||
log.Printf("fpath:'%s'", fpath)
|
log.Printf("fPath:'%s'", fPath)
|
||||||
|
|
||||||
fi, err := os.Stat(fpath)
|
fi, err := os.Stat(fPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFile(fi) {
|
if isFile(fi) {
|
||||||
http.ServeFile(w, req, fpath)
|
http.ServeFile(w, req, fPath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := getContent(req, fpath)
|
content, err := getContent(req, fPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ func makeFeed(dirpath string, req *http.Request) atom.Feed {
|
|||||||
|
|
||||||
fis, _ := ioutil.ReadDir(dirpath)
|
fis, _ := ioutil.ReadDir(dirpath)
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
pathType := getPathType(filepath.Join(dirpath, fi.Name()))
|
pathType := getPathType(path.Join(dirpath, fi.Name()))
|
||||||
feedBuilder = feedBuilder.
|
feedBuilder = feedBuilder.
|
||||||
AddEntry(opds.EntryBuilder.
|
AddEntry(opds.EntryBuilder.
|
||||||
ID(req.URL.Path + fi.Name()).
|
ID(req.URL.Path + fi.Name()).
|
||||||
@ -167,7 +167,7 @@ func getType(name string, pathType int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHref(req *http.Request, name string) string {
|
func getHref(req *http.Request, name string) string {
|
||||||
return filepath.Join(req.URL.RequestURI(), url.PathEscape(name))
|
return path.Join(req.URL.RequestURI(), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user