mirror of
https://github.com/nkanaev/yarr.git
synced 2025-07-08 16:00:11 +00:00
serve template & static files
This commit is contained in:
parent
29b860470b
commit
7c9f182ba2
6
main.go
6
main.go
@ -1,18 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nkanaev/yarr/storage"
|
//"github.com/nkanaev/yarr/storage"
|
||||||
//"github.com/nkanaev/yarr/worker"
|
//"github.com/nkanaev/yarr/worker"
|
||||||
"github.com/nkanaev/yarr/server"
|
"github.com/nkanaev/yarr/server"
|
||||||
"log"
|
//"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
/*
|
||||||
store, err := storage.New()
|
store, err := storage.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
log.Print(store)
|
log.Print(store)
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
folder := store.CreateFolder("foo")
|
folder := store.CreateFolder("foo")
|
||||||
store.RenameFolder(folder.Id, "bar")
|
store.RenameFolder(folder.Id, "bar")
|
||||||
|
@ -1,13 +1,37 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"log"
|
||||||
|
"io"
|
||||||
|
"fmt"
|
||||||
|
"mime"
|
||||||
|
)
|
||||||
|
|
||||||
func Index(rw http.ResponseWriter, req *http.Request) {
|
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) {
|
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) {
|
func FolderList(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user