You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
best routing, static files embedding
This commit is contained in:
21
edit/edit.go
21
edit/edit.go
@@ -4,9 +4,12 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/page"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
type editPage struct {
|
||||
Var1 string
|
||||
}
|
||||
|
||||
// Execute sth
|
||||
@@ -14,15 +17,23 @@ func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) {
|
||||
if r.Method == "POST" {
|
||||
// it's saving the post
|
||||
} else {
|
||||
// check if the file exists
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
file, _ := ioutil.ReadFile(file)
|
||||
file, err := ioutil.ReadFile(file)
|
||||
|
||||
// render the template here
|
||||
w.Write([]byte(string(file)))
|
||||
if err != nil {
|
||||
return 500, err
|
||||
}
|
||||
|
||||
editInfo := new(editPage)
|
||||
editInfo.Var1 = string(file)
|
||||
|
||||
page := new(page.Info)
|
||||
page.Title = "Edit"
|
||||
page.Body = editInfo
|
||||
return page.Render("edit", w)
|
||||
}
|
||||
|
||||
return 200, nil
|
||||
|
||||
Reference in New Issue
Block a user