notes-server/server/notes.go

30 lines
484 B
Go

package server
import (
"local/notes-server/config"
"net/http"
"path"
"strings"
)
func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
path := resolvePath(r.URL.Path)
if isDir(path) {
head(w, r)
notesDir(path, w, r)
foot(w, r)
} else if isFile(path) {
head(w, r)
notesFile(path, w, r)
foot(w, r)
} else {
http.NotFound(w, r)
}
}
func resolvePath(p string) string {
p = strings.TrimPrefix(p, "/notes/")
p = path.Join(config.Root, p)
return p
}