removed static files handler

This commit is contained in:
Suraj 2016-02-01 20:04:01 +05:30
parent 5f38eb7c52
commit 5b60435ee0
1 changed files with 2 additions and 31 deletions

View File

@ -1,10 +1,9 @@
package views package views
/*Holds the fetch related view handlers*/
import ( import (
"bufio"
"net/http" "net/http"
"os"
"strings"
"text/template" "text/template"
"time" "time"
@ -74,31 +73,3 @@ func ShowCompleteTasksFunc(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
} }
} }
//ServeStaticFunc is used to serve static files
//TODO: replace this with the http.FileServer
func ServeStaticFunc(w http.ResponseWriter, r *http.Request) {
path := "./public" + r.URL.Path
var contentType string
if strings.HasSuffix(path, ".css") {
contentType = "text/css"
} else if strings.HasSuffix(path, ".png") {
contentType = "image/png"
} else if strings.HasSuffix(path, ".js") {
contentType = "application/javascript"
} else {
contentType = "plain/text"
}
f, err := os.Open(path)
if err == nil {
defer f.Close()
w.Header().Add("Content Type", contentType)
br := bufio.NewReader(f)
br.WriteTo(w)
} else {
w.WriteHeader(404)
}
}