3 Star 0 Fork 0

go_projects/edgex_back_management

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
thank 提交于 2018-11-12 15:04 . add: Edgex Foundry中文社區完成版
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go_projects/edgex_back_management.git
[email protected]:go_projects/edgex_back_management.git
go_projects
edgex_back_management
edgex_back_management
master

搜索帮助