代码拉取完成,页面将自动刷新
package main
import (
"edgex_back_management/defs"
"edgex_back_management/handlers"
"edgex_back_management/session"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
type middleWareHandler struct {
r *httprouter.Router
}
func NewMiddleWareHandler(r *httprouter.Router) http.Handler {
m := middleWareHandler{}
m.r = r
return m
}
func (m middleWareHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// check session
ok := handlers.ValidateUserSession(r)
if ok {
m.r.ServeHTTP(w, r)
} else {
defs.SendErrorResponse(w, defs.ErrorAuthExpired)
}
}
func RegisterHandlers() *httprouter.Router {
router := httprouter.New()
router.GET("/", handlers.IndexHandler)
router.POST("/user/login", handlers.Login)
router.GET("/user/home", handlers.HomeHandler)
router.GET("/user/logout/:userName", handlers.Logout)
router.GET("/user/getByName/:userName", handlers.FindUserInfo)
router.GET("/article/getArticle/:id", handlers.GetArticle)
router.GET("/articles/:from/:size", handlers.FindAllArticle)
router.GET("/article/passArticle/:id", handlers.PassArticle)
router.GET("/article/rejectArticle/:id", handlers.RejectArticle)
router.GET("/article/deleteArticle/:id", handlers.DeleteArticle)
router.ServeFiles("/statics/*filepath", http.Dir("./templates"))
return router
}
func loadSessionCache() {
ok := session.LoadAndCacheSessions()
if ok {
log.Printf("User Sessions Load successed!")
}
}
func main() {
loadSessionCache()
r := RegisterHandlers()
handler := NewMiddleWareHandler(r)
//ok := dbops.DBConnect()
//ok := true
//if ok {
// log.Println("connect to db success!")
//} else {
// log.Println("failed connect to db!")
//}
log.Println("Server Listening :Port(8080)")
http.ListenAndServe(":8080", handler)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。