go - 多路复用路由器在 debian 拉伸(linux)上返回错误 503,适用于 Windows 10
问题描述
我在 Linux 服务器上遇到了一个奇怪的问题,当我运行我的应用程序并导航到它时,它给了我错误 503 服务不可用。
我正在使用 mux 路由器,它在 Windows 上运行良好,但在 Linux 上由于某种原因它不能。
我将路由传递给完成处理程序的中间件,就像这样......
中间件.go
func SetRoute(r *mux.Router, uri string, handle func(http.ResponseWriter, *http.Request), methods string) {
r.HandleFunc(uri, handle).Methods(methods)
r.Use(MiddlewareHandle)
}
func MiddlewareHandle(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
defer func() {
log.Println(r.URL.Path, time.Since(start))
}()
next.ServeHTTP(w, r)
})
}
然后对于我的路线:
r := mux.NewRouter()
middleware.SetRoute(r, "/", index.Index, "GET")
srv := &http.Server{
Handler: r,
Addr: "127.0.0.1:8080",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
我的处理方式是这样的:
type IndexData struct {
PageTitle string
}
func Index(w http.ResponseWriter, r *http.Request) {
data := IndexData{
PageTitle: "Hello World",
}
err := template.Must(template.New(BaseTemplate).Funcs(FuncTemplate).ParseFiles(BaseTemplate, "index.html")).ExecuteTemplate(w, "skeleton", data)
if err != nil {
fmt.Println(err)
}
}
知道为什么它不能在 Linux (Debian Stretch) 上运行吗?
解决方案
推荐阅读
- python - 遍历数组时遇到问题请告知
- c# - Unity 中是否有“Singletons”(持久游戏对象)的最佳实践?
- multithreading - 粗略但正确的方法来确定线程的 CPU 负载?
- azure - Azure RBAC 用于删除创建新订阅的访问权限
- python - python排序字典列表,日期字符串
- javascript - dataTables 新行不会添加到表中
- python - 这些集合如何相等?(ELI5)
- android - 如何从 LinkedHashMap 中获取键值
- javascript - 如何修复由于 js 脚本而未显示的 HTML 元素?
- css - 使用主 CSS 文件更新 Wordpress 中的 minify.css 文件