diff options
author | ache <ache@ache.one> | 2019-02-16 21:19:43 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2019-02-16 21:19:43 +0100 |
commit | f6d498043c774b1f3b4da9705e71b6a204dd29ba (patch) | |
tree | 172b02701c2e5c0f0257401dfd6248a0e679f2ad /server.go | |
parent | Handle Move method (diff) |
Method delete
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -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:] |