mime 类型初始化

@admpub 在你的 pr 基础上做了一些小重构
This commit is contained in:
Liang Ding 2014-10-24 23:51:24 +08:00
parent 5fedcd6c57
commit d11db2f3af
2 changed files with 15 additions and 8 deletions

19
main.go
View File

@ -5,11 +5,11 @@ import (
"flag"
"html/template"
"math/rand"
"mime"
"net/http"
"runtime"
"strconv"
"time"
"mime"
"github.com/b3log/wide/conf"
"github.com/b3log/wide/editor"
@ -274,14 +274,10 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) {
// 主程序入口.
func main() {
//解决Windows环境下问题
mime.AddExtensionType(".css", "text/css")
mime.AddExtensionType(".js", "application/x-javascript")
mime.AddExtensionType(".json", "application/json")
runtime.GOMAXPROCS(conf.Wide.MaxProcs)
initMime()
defer glog.Flush()
// IDE
@ -387,3 +383,12 @@ func panicRecover(handler func(w http.ResponseWriter, r *http.Request)) func(w h
handler(w, r)
}
}
// 初始化 mime.
//
// 有的操作系统(例如 Windows XP上运行时根据文件后缀获取不到对应的 mime 类型,会导致响应的 HTTP content-type 不正确。
func initMime() {
mime.AddExtensionType(".css", "text/css")
mime.AddExtensionType(".js", "application/x-javascript")
mime.AddExtensionType(".json", "application/json")
}

View File

@ -1,3 +1,5 @@
go install
wide
pause
pause