示例#1
0
func RenderResource(w http.ResponseWriter, r *http.Request) {

	resource := mux.Vars(r)["resource"]
	resourceType := mux.Vars(r)["type"]

	path := Config.Root + "web" + Config.PathSeparator + "resources" + Config.PathSeparator + resourceType + Config.PathSeparator + resource

	if fileExists(path) != true {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	file, err := ioutil.ReadFile(path)
	errors.Check(err)

	w.Header().Set("Content-Type", "text/"+resourceType)
	w.Write(file)
}
示例#2
0
func RenderPage(w http.ResponseWriter, r *http.Request) {

	view := mux.Vars(r)["view"]

	if view == "" {
		view = "index"
	}

	path := Config.Root + "web" + Config.PathSeparator + "views" + Config.PathSeparator + view + ".html"

	if fileExists(path) != true {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	template, err := ioutil.ReadFile(path)
	errors.Check(err)

	w.Write(template)
}