serve template & static files

This commit is contained in:
Nazar Kanaev 2020-06-28 00:53:35 +01:00
parent 29b860470b
commit 7c9f182ba2
2 changed files with 31 additions and 5 deletions

View File

@ -1,18 +1,20 @@
package main
import (
"github.com/nkanaev/yarr/storage"
//"github.com/nkanaev/yarr/storage"
//"github.com/nkanaev/yarr/worker"
"github.com/nkanaev/yarr/server"
"log"
//"log"
)
func main() {
/*
store, err := storage.New()
if err != nil {
log.Fatal(err)
}
log.Print(store)
*/
/*
folder := store.CreateFolder("foo")
store.RenameFolder(folder.Id, "bar")

View File

@ -1,13 +1,37 @@
package server
import "net/http"
import (
"net/http"
"os"
"log"
"io"
"fmt"
"mime"
)
func Index(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("index"))
fmt.Println(os.Getwd())
f, err := os.Open("template/index.html")
if err != nil {
log.Fatal(err)
}
defer f.Close()
rw.Header().Set("Content-Type", "text/html")
io.Copy(rw, f)
}
func Static(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("static:" + Vars(req)["path"]))
path := "template/static/" + Vars(req)["path"]
f, err := os.Open(path)
if err != nil {
rw.WriteHeader(http.StatusNotFound)
return
}
defer f.Close()
rw.Header().Set("Content-Type", mime.TypeByExtension(path))
io.Copy(rw, f)
}
func FolderList(rw http.ResponseWriter, req *http.Request) {