summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-16 21:19:43 +0100
committerache <ache@ache.one>2019-02-16 21:19:43 +0100
commitf6d498043c774b1f3b4da9705e71b6a204dd29ba (patch)
tree172b02701c2e5c0f0257401dfd6248a0e679f2ad
parentHandle Move method (diff)
Method delete
-rw-r--r--dir.html4
-rw-r--r--server.go29
2 files changed, 27 insertions, 6 deletions
diff --git a/dir.html b/dir.html
index 9c240eb..da8ab1c 100644
--- a/dir.html
+++ b/dir.html
@@ -7,13 +7,13 @@
<h1>Index of {{ .Name }}</h1><br>
<section id="main">
<pre>{{range .ListFiles}}
- <a href="{{ .Name }}">{{ .Name }}</a>{{ .Size }}{{end}}
+ <a href="{{ .Path }}">{{ .Name }}</a>{{ .Size }}{{end}}
</pre>
</section>
<section id="nav">
<h2>List of directories</h2>
<pre>{{range .ListCols}}
- <a href="{{ .Name }}">{{ .Name }}</a>{{end}}
+ <a href="{{ .Path }}">{{ .Name }}</a>{{end}}
</pre>
</section>
<section id="dav">
diff --git a/server.go b/server.go
index 13cc673..3228bef 100644
--- a/server.go
+++ b/server.go
@@ -14,12 +14,15 @@ import (
var tmpl *template.Template
+func getPath( r *http.Request ) string {
+ if r.URL.Path == "/" {
+ return "."
+ }
+ return r.URL.Path[1:]
+}
func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
+ filename := getPath(r)
- filename := r.URL.Path[1:]
- if filename == "" {
- filename = "."
- }
fmt.Printf("Trying to get [%s]\n", filename)
stat, err := os.Stat(filename)
@@ -96,6 +99,24 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
}
}
func handleDelete( w http.ResponseWriter, r *http.Request) {
+ filename := getPath(r)
+
+ _, err := os.Stat(filename)
+
+ if err != nil {
+ if os.IsNotExist(err) {
+ w.WriteHeader(http.StatusBadRequest)
+ fmt.Fprintf(w, "Bro, they is nothing here")
+ } else {
+ w.WriteHeader(http.StatusInternalServerError)
+ fmt.Fprintf(w, "Shit happen")
+ }
+ }
+ err = os.Remove(filename)
+ if err != nil {
+ w.WriteHeader(http.StatusConflict)
+ fmt.Fprintf(w, "Error : %s\n", err.Error())
+ }
}
func handlePut( w http.ResponseWriter, r *http.Request) {
filename := r.URL.Path[1:]