mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 09:55:36 +00:00
serve template & static files
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user