Beego没gin配置静态页面方便

2019-06-25 10:22:15 浏览数 (1)

上代码

腾讯这个例子还是很值得学习的,不轻有东西,单也不重到看着都蒙圈的样子。

https://github.com/Tencent/bk-cmdb/blob/master/src/web_server/service/service.go

Beego没gin配置静态页面方便

下面是gin的静态页面承载配置。

代码语言:javascript复制
 ws.Static("/static", s.Config.Site.HtmlRoot)
 ws.LoadHTMLFiles(s.Config.Site.HtmlRoot   "/index.html")

简单吧。

代码语言:javascript复制
func (s *Service) WebService() *gin.Engine {
    ws := gin.Default()

    ws.Use(sessions.Sessions(s.Config.Session.Name, s.Session))
    ws.Use(middleware.ValidLogin(*s.Config, s.Discovery()))
    middleware.Engine = s.Engine

    ws.Static("/static", s.Config.Site.HtmlRoot)
    ws.LoadHTMLFiles(s.Config.Site.HtmlRoot   "/index.html")

    ws.POST("/hosts/import", s.ImportHost)
    ws.POST("/hosts/export", s.ExportHost)
    ws.POST("/importtemplate/:bk_obj_id", s.BuildDownLoadExcelTemplate)
    ws.POST("/insts/owner/:bk_supplier_account/object/:bk_obj_id/import", s.ImportInst)
    ws.POST("/insts/owner/:bk_supplier_account/object/:bk_obj_id/export", s.ExportInst)
    ws.POST("/logout", s.LogOutUser)
    ws.POST("/object/owner/:bk_supplier_account/object/:bk_obj_id/import", s.ImportObject)
    ws.POST("/object/owner/:bk_supplier_account/object/:bk_obj_id/export", s.ExportObject)
    ws.GET("/user/list", s.GetUserList)
    ws.GET("/user/language/:language", s.UpdateUserLanguage)
    ws.GET("/userinfo", s.UserInfo)
    ws.PUT("/user/current/supplier/:id", s.UpdateSupplier)

    ws.GET("/healthz", s.Healthz)
    ws.GET("/", s.Index)
    return ws
}

0 人点赞