EasyGoAdmin_GoFrame_EleVue-1 发表于 2024-01-25 | 更新于 2024-09-02 | 分类于 Go 本文字数: 43k | 阅读时长 ≈ 39 分钟 原文地址 main.go123456789101112131415package mainimport ( _ "easygoadmin/boot" _ "easygoadmin/router" "github.com/gogf/gf/frame/g")// @title EasyGoAdmin前后端分离旗舰版框架// @version 1.0// @description EasyGoAdmin前后端分离旗舰版框架// @schemes httpfunc main() { g.Server().Run()} router router.go 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260/** * 系统路由 * @File : submit */package routerimport ( "easygoadmin/app/controller" "easygoadmin/middleware" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp")func init() { s := g.Server() // 跨域处理 s.Use(middleware.CORS) // 登录验证中间件 s.Use(middleware.CheckLogin) // 操作日志中间件 s.Use(middleware.OperLog) // 登录日志中间件 s.Use(middleware.LoginLog) /* 文件上传 */ s.Group("/upload", func(group *ghttp.RouterGroup) { // 上传图片 group.POST("/uploadImage", controller.Upload.UploadImage) }) /* 登录注册 */ s.Group("/", func(group *ghttp.RouterGroup) { group.GET("/", controller.Login.Login) group.ALL("/login", controller.Login.Login) group.GET("/captcha", controller.Login.Captcha) group.ALL("/updateUserInfo", controller.Index.UpdateUserInfo) group.ALL("/updatePwd", controller.Index.UpdatePwd) group.GET("/logout", controller.Index.Logout) }) s.Group("index", func(group *ghttp.RouterGroup) { group.GET("/menu", controller.Index.Menu) group.GET("/user", controller.Index.User) }) /* 用户管理 */ s.Group("user", func(group *ghttp.RouterGroup) { group.GET("/list", controller.User.List) group.GET("/detail", controller.User.Detail) group.POST("/add", controller.User.Add) group.PUT("/update", controller.User.Update) group.DELETE("/delete/:ids", controller.User.Delete) group.PUT("/status", controller.User.Status) group.PUT("/resetPwd", controller.User.ResetPwd) group.GET("/checkUser", controller.User.CheckUser) }) /* 职级管理 */ s.Group("level", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Level.List) group.POST("/add", controller.Level.Add) group.PUT("/update", controller.Level.Update) group.DELETE("/delete/:ids", controller.Level.Delete) group.PUT("/status", controller.Level.Status) group.GET("/getLevelList", controller.Level.GetLevelList) group.GET("/exportExcel", controller.Level.ExportExcel) group.POST("/importExcel", controller.Level.ImportExcel) group.GET("/downloadExcel", controller.Level.DownloadExcel) }) /* 岗位路由 */ s.Group("position", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Position.List) group.POST("/add", controller.Position.Add) group.PUT("/update", controller.Position.Update) group.DELETE("/delete/:ids", controller.Position.Delete) group.PUT("/status", controller.Position.Status) group.GET("/getPositionList", controller.Position.GetPositionList) }) /* 角色路由 */ s.Group("role", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Role.List) group.POST("/add", controller.Role.Add) group.PUT("/update", controller.Role.Update) group.DELETE("/delete/:ids", controller.Role.Delete) group.PUT("/status", controller.Role.Status) group.GET("/getRoleList", controller.Role.GetRoleList) }) /* 角色菜单权限 */ s.Group("rolemenu", func(group *ghttp.RouterGroup) { group.GET("/index", controller.RoleMenu.Index) group.POST("/save", controller.RoleMenu.Save) }) /* 部门管理 */ s.Group("dept", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Dept.List) group.POST("/add", controller.Dept.Add) group.PUT("/update", controller.Dept.Update) group.DELETE("/delete/:ids", controller.Dept.Delete) group.GET("/getDeptList", controller.Dept.GetDeptList) }) /* 菜单管理 */ s.Group("menu", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Menu.List) group.GET("/detail", controller.Menu.Detail) group.POST("/add", controller.Menu.Add) group.PUT("/update", controller.Menu.Update) group.DELETE("/delete/:ids", controller.Menu.Delete) }) /* 操作日志 */ s.Group("operlog", func(group *ghttp.RouterGroup) { group.GET("/list", controller.OperLog.List) }) /* 登录日志 */ s.Group("loginlog", func(group *ghttp.RouterGroup) { group.GET("/list", controller.LoginLog.List) group.DELETE("/delete/:ids", controller.LoginLog.Delete) }) /* 城市管理 */ s.Group("city", func(group *ghttp.RouterGroup) { group.GET("/list", controller.City.List) group.POST("/add", controller.City.Add) group.PUT("/update", controller.City.Update) group.DELETE("/delete/:ids", controller.City.Delete) group.POST("/getChilds", controller.City.GetChilds) }) /* 字典管理 */ s.Group("dict", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Dict.List) group.POST("/add", controller.Dict.Add) group.PUT("/update", controller.Dict.Update) group.DELETE("/delete/:ids", controller.Dict.Delete) }) /* 字典项管理 */ s.Group("dictdata", func(group *ghttp.RouterGroup) { group.GET("/list", controller.DictData.List) group.POST("/add", controller.DictData.Add) group.PUT("/update", controller.DictData.Update) group.DELETE("/delete/:ids", controller.DictData.Delete) }) /* 配置管理 */ s.Group("config", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Config.List) group.POST("/add", controller.Config.Add) group.PUT("/update", controller.Config.Update) group.DELETE("/delete/:ids", controller.Config.Delete) }) /* 配置项管理 */ s.Group("configdata", func(group *ghttp.RouterGroup) { group.GET("/list", controller.ConfigData.List) group.POST("/add", controller.ConfigData.Add) group.PUT("/update", controller.ConfigData.Update) group.DELETE("/delete/:ids", controller.ConfigData.Delete) group.PUT("/status", controller.ConfigData.Status) }) /* 友链管理 */ s.Group("link", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Link.List) group.POST("/add", controller.Link.Add) group.PUT("/update", controller.Link.Update) group.DELETE("/delete/:ids", controller.Link.Delete) group.PUT("/status", controller.Link.Status) }) /* 站点管理 */ s.Group("item", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Item.List) group.POST("/add", controller.Item.Add) group.PUT("/update", controller.Item.Update) group.DELETE("/delete/:ids", controller.Item.Delete) group.PUT("/status", controller.Item.Status) group.GET("/getItemList", controller.Item.GetItemList) }) /* 栏目管理 */ s.Group("itemcate", func(group *ghttp.RouterGroup) { group.GET("/list", controller.ItemCate.List) group.POST("/add", controller.ItemCate.Add) group.PUT("/update", controller.ItemCate.Update) group.DELETE("/delete/:ids", controller.ItemCate.Delete) //group.GET("/getCateTreeList", controller.ItemCate.GetCateTreeList) group.GET("/getCateList", controller.ItemCate.GetCateList) }) /* 广告位管理 */ s.Group("adsort", func(group *ghttp.RouterGroup) { group.GET("/list", controller.AdSort.List) group.POST("/add", controller.AdSort.Add) group.PUT("/update", controller.AdSort.Update) group.DELETE("/delete/:ids", controller.AdSort.Delete) group.GET("/getAdSortList", controller.AdSort.GetAdSortList) }) /* 广告管理 */ s.Group("ad", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Ad.List) group.POST("/add", controller.Ad.Add) group.PUT("/update", controller.Ad.Update) group.DELETE("/delete/:ids", controller.Ad.Delete) group.PUT("/status", controller.Ad.Status) }) /* 通知管理 */ s.Group("notice", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Notice.List) group.POST("/add", controller.Notice.Add) group.PUT("/update", controller.Notice.Update) group.DELETE("/delete/:ids", controller.Notice.Delete) group.PUT("/status", controller.Notice.Status) }) /* 网站设置 */ s.Group("configweb", func(group *ghttp.RouterGroup) { group.GET("/index", controller.ConfigWeb.Index) group.PUT("/save", controller.ConfigWeb.Save) }) /* 会员等级 */ s.Group("memberlevel", func(group *ghttp.RouterGroup) { group.GET("/list", controller.MemberLevel.List) group.POST("/add", controller.MemberLevel.Add) group.PUT("/update", controller.MemberLevel.Update) group.DELETE("/delete/:ids", controller.MemberLevel.Delete) group.GET("/getMemberLevelList", controller.MemberLevel.GetMemberLevelList) }) /* 会员管理 */ s.Group("member", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Member.List) group.POST("/add", controller.Member.Add) group.PUT("/update", controller.Member.Update) group.DELETE("/delete/:ids", controller.Member.Delete) group.PUT("/status", controller.Member.Status) }) /* 统计分析 */ s.Group("analysis", func(group *ghttp.RouterGroup) { group.GET("/index", controller.Analysis.Index) }) /* 代码生成器 */ s.Group("generate", func(group *ghttp.RouterGroup) { group.GET("/list", controller.Generate.List) group.POST("/generate", controller.Generate.Generate) group.POST("/batchGenerate", controller.Generate.BatchGenerate) })} middleware checklogin.go 123456789101112131415161718192021222324252627282930313233343536373839404142/** * 登录验证中间件 * @File : checklogin */package middlewareimport ( "easygoadmin/app/utils" "easygoadmin/app/utils/common" "fmt" "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/text/gstr" "time")func CheckLogin(r *ghttp.Request) { fmt.Println("登录验证中间件") // 放行设置 urlItem := []string{"/captcha", "/login"} if !utils.InStringArray(r.RequestURI, urlItem) { // 从请求头中获取Token token := r.GetHeader("Authorization") // 字符串替换 token = gstr.Replace(token, "Bearer ", "") claim, err := utils.ParseToken(token) if err != nil { fmt.Println("解析token出现错误:", err) r.Response.WriteJsonExit(common.JsonResult{ Code: 401, Msg: "Token已过期", }) } else if time.Now().Unix() > claim.ExpiresAt { fmt.Println("时间超时") r.Response.WriteJsonExit(common.JsonResult{ Code: 401, Msg: "时间超时", }) } } // 前置中间件 r.Middleware.Next()}