summaryrefslogtreecommitdiff
path: root/server.go
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 /server.go
parentHandle Move method (diff)
Method delete
Diffstat (limited to 'server.go')
-rw-r--r--server.go29
1 files changed, 25 insertions, 4 deletions
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:]