router.go 2.8 KB
package routers

import (
	"oppmg/controllers"

	"oppmg/middleware"

	"github.com/astaxie/beego"
)

func init() {
	nsV1 := beego.NewNamespace("v1",
		beego.NSBefore(middleware.AllowOption),
		beego.NSBefore(middleware.LogRequestData),
		beego.NSBefore(middleware.AuthToken),
		beego.NSNamespace("/company",
			beego.NSRouter("/department", &controllers.CompanyController{}, "get:DepartmentList"),
			beego.NSRouter("/department/:id([0-9]+)", &controllers.CompanyController{}, "get:DepartmentOne"),
			beego.NSRouter("/department", &controllers.CompanyController{}, "post:DepartmentAdd"),
			beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"),
			beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"),
			beego.NSRouter("/position", &controllers.CompanyController{}, "get:PositionList"),
			beego.NSRouter("/position", &controllers.CompanyController{}, "post:PositionAdd"),
			beego.NSRouter("/position", &controllers.CompanyController{}, "put:PositionEdit"),
			beego.NSRouter("/position", &controllers.CompanyController{}, "delete:PositionDelete"),
		),
		beego.NSNamespace("/rbac",
			beego.NSRouter("/role", &controllers.RbacController{}, "post:RoleAdd"),
			beego.NSRouter("/role", &controllers.RbacController{}, "put:RoleUpdate"),
			beego.NSRouter("/role", &controllers.RbacController{}, "delete:RoleDelete"),
			beego.NSRouter("/role_group", &controllers.RbacController{}, "post:RoleGroupAdd"),
			beego.NSRouter("/role_group", &controllers.RbacController{}, "put:RoleGroupUpdate"),
			beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"),
			beego.NSRouter("/:companyid([0-9]+)/role", &controllers.RbacController{}, "get:RoleList"),
		),
		beego.NSNamespace("/auth",
			beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"),
			beego.NSRouter("/refresh_token", &controllers.AuthController{}, "get:RefreshToken"),
		),
		beego.NSNamespace("/bulletin",
			beego.NSRouter("/add", &controllers.BulletinController{}, "post:BulletinRelease"),
			beego.NSRouter("/list", &controllers.BulletinController{}, "post:BulletinList"),
			beego.NSRouter("/:id([0-9]+)", &controllers.BulletinController{}, "get:GetBulletin"),
			beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"),
		),
	)

	nsAuth := beego.NewNamespace("/auth",
		beego.NSBefore(middleware.AllowOption),
		beego.NSBefore(middleware.LogRequestData),
		beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"),
	)
	beego.AddNamespace(nsV1)
	beego.AddNamespace(nsAuth)
}

//routerPermission 路由对应的权限
// var routerPermission = map[string]string{
// 	"get:/v1/company/:companyid/position": "show",
// 	"post:/v1/company/position":           "add",
// 	"put:/v1/company/position":            "edit",
// 	"delete:/v1/company/position":         "delete",
// }