目录结构

代码
package main
import (
"html/template"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"runtime/debug"
"strings"
)
const (
ListDir = 0x0001
UploadDir = "./uploads"
TemplateDir = "./views"
)
var templates = make(map[string]*template.Template)
func init() {
fileInfoArr, err := ioutil.ReadDir(TemplateDir)
check(err)
var templateName, templatePath string
for _, fileInfo := range fileInfoArr {
templateName = fileInfo.Name()
if ext := path.Ext(templateName); ext != ".html" {
continue
}
tmpl := strings.Split(templateName,".")[0]
templatePath = TemplateDir + "/" + templateName
log.Println("Loading template:", templatePath)
t := template.Must(template.ParseFiles(templatePath))
templates[tmpl] = t
}
}
func check(err error) {
if err != nil {
panic(err)
}
}
func renderHtml(w http.ResponseWriter, tmpl string, locals map[string]interface{
}) {
err := templates