set some default headers
This commit is contained in:
parent
0b670c1194
commit
20dd050863
19
server.go
19
server.go
|
@ -9,8 +9,25 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
func setContentType(w http.ResponseWriter, ext string) {
|
||||
var t string
|
||||
switch ext {
|
||||
case ".html":
|
||||
t = "text/html"
|
||||
case ".js":
|
||||
t = "text/javascript"
|
||||
default:
|
||||
t = ""
|
||||
}
|
||||
if t != "" {
|
||||
w.Header().Add("Content-Type", t)
|
||||
}
|
||||
}
|
||||
|
||||
func viewHandler(root string, w http.ResponseWriter, r *http.Request) {
|
||||
file := filepath.Join(root, filepath.FromSlash(r.URL.Path[1:]))
|
||||
relativePath := filepath.FromSlash(r.URL.Path[1:])
|
||||
file := filepath.Join(root, relativePath)
|
||||
setContentType(w, filepath.Ext(relativePath))
|
||||
info, err := os.Stat(file)
|
||||
if err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user