【发布时间】:2019-10-02 00:03:01
【问题描述】:
我正在尝试在不使用任何框架的情况下在 golang 中创建一个 MVC Web 应用程序。我打算如何实现它是使用 http.NewServeMux() 创建一个 http.Server {} 的实例,因为它的处理程序如下所示:
sm := http.NewServeMux()
sm.Handle("/route1", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/front-office/index.html")
}))
sm.Handle("/route2", handleSomething())
sm.Handle("/route3", handleSomething())
sm.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
frontEndUIServer := http.Server{
Addr: ":9000",
Handler: sm,
}
go frontEndUIServer.ListenAndServe()
然后使属性sm 可导出,以便任何其他 go 文件可以导入它并在其上创建处理程序,从而实现我的控制器。由于我是 goLang 的新手,我现在的问题是如何使属性 sm 可导出?
【问题讨论】: