feat: modularize the code.
This commit is contained in:
parent
6f4757a1e9
commit
a59c892087
7 changed files with 293 additions and 243 deletions
22
delete.go
Normal file
22
delete.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Delete(c echo.Context) error {
|
||||
file := c.Param("file")
|
||||
filePath := "files/" + file
|
||||
|
||||
if _, err := os.Stat(filePath); err != nil {
|
||||
return c.String(http.StatusOK, "That file doesn't exist on the server\n")
|
||||
}
|
||||
|
||||
err := os.Remove(filePath)
|
||||
if err != nil {
|
||||
return c.String(http.StatusOK, "Error while deleting "+file+"\n")
|
||||
}
|
||||
return c.String(http.StatusOK, "Deleted file from server: "+file+"\n")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue