当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"strings"
"team/common/web"
"team/config"
"team/controller"
"team/middleware"
rice "github.com/GeertJohan/go.rice"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// Load configuration.
config.Load()
// Load resources.
resBox := rice.MustFindBox("view/dist")
mainPage := strings.ReplaceAll(resBox.MustString("app.html"), "__APP_NAME__", config.App.Name)
// Create router for httpd service.
router := web.NewRouter()
router.Use(middleware.Logger)
router.Use(middleware.PanicAsError)
// Statics.
router.SetPage("/", mainPage)
router.StaticFS("/assets", resBox.HTTPBox())
router.StaticFS("/uploads", web.Dir("uploads"))
// Home. Determine display mode.
router.GET("/home", controller.Home)
// Install/Login/Logout API.
router.UseController("/install", new(controller.Install), middleware.MustNotInstalled)
router.GET("/logout", controller.Logout, middleware.MustInstalled)
router.POST("/login", controller.Login, middleware.MustInstalled)
// Normal API.
api := router.Group("/api")
api.Use(middleware.MustInstalled)
api.Use(middleware.AutoLogin)
api.Use(middleware.MustLogined)
api.UseController("/user", new(controller.User))
api.UseController("/task", new(controller.Task))
api.UseController("/project", new(controller.Project))
api.UseController("/document", new(controller.Document))
api.UseController("/file", new(controller.File))
api.UseController("/notice", new(controller.Notice))
// Admin API.
router.UseController(
"/admin",
new(controller.Admin),
middleware.MustInstalled,
middleware.AutoLogin,
middleware.MustLoginedAsAdmin)
// Start service.
router.Start(config.App.Addr())
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化