上代碼html
騰訊這個例子仍是很值得學習的,不輕有東西,單也不重到看着都蒙圈的樣子。git
https://github.com/Tencent/bk-cmdb/blob/master/src/web_server/service/service.gogithub
Beego沒gin配置靜態頁面方便web
下面是gin的靜態頁面承載配置。session
ws.Static("/static", s.Config.Site.HtmlRoot) ws.LoadHTMLFiles(s.Config.Site.HtmlRoot + "/index.html")
簡單吧。學習
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 }