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