Exemplo n.º 1
0
func init() {
	fmt.Println("start route config")
	beego.Router("/", &controllers.MainController{})
	//beego.Router("/post", &controllers.PostController{})
	//beego.Router("/user", &controllers.UserController{})

	ns := beego.NewNamespace("/v1",
		beego.NSCond(func(ctx *context.Context) bool {
			//if ctx.Input.Domain() == "api.genffy.com" {
			//	return true
			//}
			//return false
			fmt.Println(ctx.Input.Domain())
			return true
		}),
		// beego.NSRouter("/index", &controllers.MainController{}, "get:ShowAPIVersion"),
		// beego.NSBefore(auth),
		beego.NSNamespace("/post",
			beego.NSInclude(
				// 对应的注解路由
				&controllers.PostController{},
			),
		),
		beego.NSNamespace("/auth",
			beego.NSInclude(
				&controllers.UserController{},
			),
		),
		beego.NSNamespace("/comment",
			beego.NSInclude(
				&controllers.CommentController{},
			),
		),
		beego.NSNamespace("/meta",
			beego.NSInclude(
				&controllers.MetaController{},
			),
		),
		// 测试超时
		// beego.NSNamespace("test",
		// 	beego.NSInclude(
		// 		&controllers.TestController{},
		// 	),
		// ),
	)
	beego.AddNamespace(ns)
}
Exemplo n.º 2
0
func init() {
	/**
	 * https://base.jream.lu/v1/url/goshorten.json
	 * https://base.jream.lu/v1/url/goexpand.json
	 */
	base := beego.NewNamespace("/v1",
		beego.NSCond(func(ctx *context.Context) bool {
			if ctx.Input.Domain() == beego.AppConfig.String("baseDomain") {
				return true
			}
			return false
		}),
		beego.NSNamespace("url",
			beego.NSRouter("/goshorten.json", &controllers.UrlController{}, "post:GoShorten"),
			beego.NSRouter("/goshorten", &controllers.UrlController{}, "post:GoShorten"),
			beego.NSRouter("/goexpand.json", &controllers.UrlController{}, "post:GoExpand"),
			beego.NSRouter("/goexpand", &controllers.UrlController{}, "post:GoExpand"),
		),
		beego.NSRouter("/object", &controllers.ObjectController{}, "post:Post"),
		beego.NSRouter("/test", &controllers.TesController{}, "post:Post"),
	)

	beego.AddNamespace(base)
}
Exemplo n.º 3
0
func router() {
	authR := beego.NewNamespace("/auth",
		beego.NSCond(func(ctx *context.Context) bool {
			if ctx.Input.Domain() == "api.beego.me" {
				return true
			}
			commonFilter(ctx)
			return true
		}),
		// beego.NSBefore(func(ctx *context.Context) {
		// beego.Debug("path=>", ctx.Request.URL.Path)
		// services.etInstance().AuthService.WithContext(ctx, func() {
		// if services.GetInstance().AuthService.HasLogin() {
		// ctx.Redirect(200, "/admin/index")
		// }
		// })
		// }),
		beego.NSRouter("/login", &controllers.AuthController{}, "*:Login"),
		beego.NSRouter("/logout", &controllers.AuthController{}, "*:Logout"),
	)

	adminR := beego.NewNamespace("/admin",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
			services.GetInstance().AuthService.WithContext(ctx, func() {
				if !services.GetInstance().AuthService.HasLogin() {
					ctx.Redirect(302, "/auth/login")
				}
			})
		}),
		beego.NSRouter("/index", &controllers.AdminController{}, "*:Index"),
		beego.NSNamespace("/user",
			beego.NSGet("/info/:id", func(ctx *context.Context) {
				ctx.Output.Body([]byte("shopinfo"))
			}),
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:UserList"),
			beego.NSRouter("/operate/?:userId", &controllers.AdminController{}, "*:UserOperate"),
			beego.NSRouter("/delete/:userId", &controllers.AdminController{}, "Get:UserDelete"),
		),
		beego.NSNamespace("/agent",
			beego.NSRouter("/list", &controllers.AdminController{}, "Get:AgentList"),
			beego.NSRouter("/operate/?:agentId", &controllers.AdminController{}, "*:AgentOperate"),
			beego.NSRouter("/delete/:agentId", &controllers.AdminController{}, "Get:AgentDelete"),
			beego.NSRouter("/:agentId/cmd/list", &controllers.AdminController{}, "Get:CmdList"),
			beego.NSRouter("/:agentId/cmd/operate", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/:agentId/cmd/operate/?:cmdId", &controllers.AdminController{}, "*:CmdOperate"),
			beego.NSRouter("/cmd/delete/:cmdId", &controllers.AdminController{}, "Get:CmdDelete"),
		),
		beego.NSNamespace("/ssh",
			beego.NSRouter("/:agentId", &controllers.AdminController{}, "Get:SshIndex"),
			beego.NSRouter("/join/:agentId", &controllers.AdminController{}, "*:SshJoin"),
			beego.NSRouter("/list", &controllers.AdminController{}, "*:SshList"),
		),
		beego.NSNamespace("/server",
			beego.NSRouter("/index/?:serverId", &controllers.ServerController{}, "Get:Index"),
			beego.NSRouter("/operate/?:serverId", &controllers.ServerController{}, "*:Operate"),
			beego.NSRouter("/delete/:serverId", &controllers.ServerController{}, "Get:Delete"),
		),
	)

	guestR := beego.NewNamespace("/guest",
		beego.NSBefore(func(ctx *context.Context) {
			commonFilter(ctx)
		}),
		beego.NSNamespace("/server",
			beego.NSRouter("/share/:serverId", &controllers.ServerController{}, "Get:Share"),
			beego.NSRouter("/:serverId/active/:apiParamId", &controllers.ServerController{}, "*:Active"),
			beego.NSRouter("/:serverId/encode/:apiParamId", &controllers.ServerController{}, "Post:Encode"),
			beego.NSRouter("/info", &controllers.ServerController{}, "Get:Info"),
		),
	)

	//注册namespace
	beego.AddNamespace(authR, adminR, guestR)

}
Exemplo n.º 4
0
func ConfigRoutes() {

	beego.Router("/root", &UserController{}, "get:CreateRoot")

	beego.Router("/auth/login", &AuthController{}, "get:LoginGet;post:LoginPost")
	beego.Router("/auth/register", &AuthController{}, "get:RegisterGet;post:RegisterPost")

	beego.Router("/sso/sig", &SsoController{}, "get:Sig")
	beego.Router("/sso/user/:sig:string", &SsoController{}, "get:User")
	beego.Router("/sso/logout/:sig:string", &SsoController{}, "get:Logout")

	beego.Router("/user/query", &UserController{}, "get:Query")
	beego.Router("/user/in", &UserController{}, "get:In")
	beego.Router("/user/qrcode/:id:int", &UserController{}, "get:QrCode")
	beego.Router("/about/:name:string", &UserController{}, "get:About")

	beego.Router("/team/users", &TeamController{}, "get:Users")
	beego.Router("/team/query", &TeamController{}, "get:Query")
	beego.Router("/team/all", &TeamController{}, "get:All")

	loginRequired :=
		beego.NewNamespace("/me",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser),
			beego.NSRouter("/logout", &AuthController{}, "*:Logout"),
			beego.NSRouter("/info", &UserController{}, "get:Info"),
			beego.NSRouter("/profile", &UserController{}, "get:ProfileGet;post:ProfilePost"),
			beego.NSRouter("/chpwd", &UserController{}, "*:ChangePassword"),
			beego.NSRouter("/users", &UserController{}, "get:Users"),
			beego.NSRouter("/user/c", &UserController{}, "get:CreateUserGet;post:CreateUserPost"),
			beego.NSRouter("/teams", &TeamController{}, "get:Teams"),
			beego.NSRouter("/team/c", &TeamController{}, "get:CreateTeamGet;post:CreateTeamPost"),
		)

	beego.AddNamespace(loginRequired)

	targetUserRequired :=
		beego.NewNamespace("/target-user",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetUser),
			beego.NSRouter("/delete", &UserController{}, "*:DeleteUser"),
			beego.NSRouter("/edit", &UserController{}, "get:EditGet;post:EditPost"),
			beego.NSRouter("/chpwd", &UserController{}, "post:ResetPassword"),
			beego.NSRouter("/role", &UserController{}, "*:Role"),
		)

	beego.AddNamespace(targetUserRequired)

	targetTeamRequired :=
		beego.NewNamespace("/target-team",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetTeam),
			beego.NSRouter("/delete", &TeamController{}, "*:DeleteTeam"),
			beego.NSRouter("/edit", &TeamController{}, "get:EditGet;post:EditPost"),
		)

	beego.AddNamespace(targetTeamRequired)

}
Exemplo n.º 5
0
Arquivo: router.go Projeto: grr89/hrkb
func init() {

	beego.Router("/", &ctrls.Cand{}, "get:Index")
	beego.InsertFilter("/", beego.BeforeRouter, FilterUser)

	beego.Router("/login", &ctrls.Main{})
	beego.Router("/logout", &ctrls.Main{}, "get:Logout")

	ns :=
		beego.NewNamespace("/adm",
			beego.NSBefore(func(ctx *context.Context) {

				_, ok := ctx.Input.Session("uid").(int)

				if !ok {
					ctx.Redirect(302, "/login")
				}

			}),
			beego.NSNamespace("/users",
				beego.NSCond(FilterAdmin),
				beego.NSRouter("/list", &ctrls.User{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.User{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.User{}),
				beego.NSRouter("/:id:int/remove", &ctrls.User{}, "get:Remove"),
			),
			beego.NSNamespace("/dep",
				beego.NSRouter("/list", &ctrls.Dep{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.Dep{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.Dep{}),
				beego.NSRouter("/:id:int/remove", &ctrls.Dep{}, "get:Remove"),
			),
			beego.NSNamespace("/crit",
				beego.NSRouter("/list", &ctrls.Crit{}, "get:Index"),
				beego.NSRouter("/:id:int", &ctrls.Crit{}),
				beego.NSRouter("/add", &ctrls.Crit{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int/remove", &ctrls.Crit{}, "get:Remove"),
			),
			beego.NSNamespace("/candidates",
				beego.NSRouter("/list", &ctrls.Cand{}, "get:Index"),
				beego.NSRouter("/add", &ctrls.Cand{}, "get:Add;post:Post"),
				beego.NSRouter("/:id:int", &ctrls.Cand{}),
				beego.NSRouter("/:id:int/files", &ctrls.Download{}, "get:Index"),
				beego.NSRouter("/:id:int/contacts", &ctrls.Contact{}, "get:Index"),
				beego.NSRouter("/:id:int/contacts/add", &ctrls.Contact{}, "post:Add"),
				beego.NSRouter("/:id:int/contacts/:cid/remove", &ctrls.Contact{}, "get:Remove"),
				beego.NSRouter("/:id:int/edit", &ctrls.Cand{}, "get:Edit"),
				beego.NSRouter("/:id:int/remove", &ctrls.Cand{}, "get:Remove"),
			),
			beego.NSNamespace("/ratings",
				beego.NSRouter("/:id:int", &ctrls.Rat{}),
				beego.NSRouter("/detailed/:id:int", &ctrls.Rat{}, "get:GetDetailed"),
				beego.NSRouter("/my/:id:int", &ctrls.Rat{}, "get:GetUserRatings"),
				beego.NSRouter("/:id:int/remove", &ctrls.Rat{}, "get:Remove"),
			),
			beego.NSNamespace("/trash",
				beego.NSCond(FilterAdmin),
				beego.NSRouter("/list", &ctrls.Trash{}),
				beego.NSRouter("/restore/:type/:id", &ctrls.Trash{}, "get:Restore"),
			),

			beego.NSNamespace("/langs",
				beego.NSRouter("/list", &ctrls.Lang{}, "get:Index"),
				beego.NSRouter("/:id:int/set_default", &ctrls.Lang{}, "get:Default"),
				beego.NSRouter("/:id:int/remove", &ctrls.Lang{}, "get:Remove"),
				beego.NSRouter("/:id:int/upload", &ctrls.Lang{}, "post:Upload"),
				beego.NSRouter("/:id:int/download", &ctrls.Lang{}, "get:Download"),
				beego.NSRouter("/add", &ctrls.Lang{}, "post:Add"),
			),
			beego.NSNamespace("/issues",
				beego.NSRouter("/labels", &ctrls.Issue{}, "get:GetLabels"),
				beego.NSRouter("/report", &ctrls.Issue{}, "post:ReportIssue"),
			),

			beego.NSNamespace("/comments",
				beego.NSRouter("/:id:int", &ctrls.Comments{}),
				beego.NSRouter("/:id:int/edit", &ctrls.Comments{}, "post:Edit"),
				beego.NSRouter("/:id:int/remove", &ctrls.Comments{}, "get:Remove"),
			),
			beego.NSRouter("/search", &ctrls.Cand{}, "get:Search"),
			beego.NSRouter("/profile", &ctrls.Prof{}),

			beego.NSRouter("/upload/:id:int", &ctrls.Upload{}, "post:Index"),
			beego.NSRouter("/upload/img/:id:int", &ctrls.Upload{}, "post:Img"),
			beego.NSRouter("/download/:id:int", &ctrls.Download{}, "get:Get"),
			beego.NSRouter("/download/:id:int/remove", &ctrls.Download{}, "post:Remove"),
			beego.NSRouter("/ratings/:id:int", &ctrls.Rat{}),
			beego.NSRouter("/ratings/detailed/:id:int", &ctrls.Rat{}, "get:GetDetailed"),
			beego.NSRouter("/ratings/my/:id:int", &ctrls.Rat{}, "get:GetUserRatings"),
			beego.NSRouter("/ratings/:id:int/remove", &ctrls.Rat{}, "get:Remove"),
			beego.NSNamespace("/debug",
				beego.NSRouter("/lastlog", &ctrls.Debug{}, "get:LastLog"),
			),
		)

	beego.AddNamespace(ns)
}
Exemplo n.º 6
0
func ConfigRoutes() {

	//open-falcon's routes
	beego.Router("/root", &UserController{}, "get:CreateRoot")
	beego.Router("/auth/login", &AuthController{}, "get:LoginGet;post:LoginPost")
	beego.Router("/auth/login/:token", &AuthController{}, "get:LoginWithToken")
	beego.Router("/auth/third-party", &AuthController{}, "post:LoginThirdParty")
	beego.Router("/auth/register", &AuthController{}, "get:RegisterGet;post:RegisterPost")

	beego.Router("/sso/sig", &SsoController{}, "get:Sig")
	beego.Router("/sso/user/:sig:string", &SsoController{}, "get:User")
	beego.Router("/sso/logout/:sig:string", &SsoController{}, "get:Logout")

	beego.Router("/user/query", &UserController{}, "get:Query")
	beego.Router("/user/in", &UserController{}, "get:In")
	beego.Router("/user/qrcode/:id:int", &UserController{}, "get:QrCode")
	beego.Router("/about/:name:string", &UserController{}, "get:About")

	beego.Router("/team/users", &TeamController{}, "get:Users")
	beego.Router("/team/query", &TeamController{}, "get:Query")
	beego.Router("/team/all", &TeamController{}, "get:All")

	//owl-protal-routes
	apins := beego.NewNamespace("/api/v1/auth",
		beego.NSGet("/notallowed", func(ctx *context.Context) {
			ctx.Output.Body([]byte("notAllowed"))
		}),
		beego.NSRouter("/register", &AuthApiController{}, "post:Register"),
		beego.NSRouter("/login", &AuthApiController{}, "post:Login"),
		beego.NSRouter("/sessioncheck", &AuthApiController{}, "get:AuthSession;post:AuthSession"),
		beego.NSRouter("/logout", &AuthApiController{}, "get:Logout;post:Logout"),
		beego.NSRouter("/user", &AuthApiController{}, "post:GetUser"),
		beego.NSRouter("/user/update", &AuthApiController{}, "put:UpdateUser;post:UpdateUser"),
		beego.NSRouter("/team/count", &AuthApiController{}, "get:CountNumOfTeam;post:CountNumOfTeam"),
	)
	beego.AddNamespace(apins)

	loginRequired :=
		beego.NewNamespace("/me",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser),
			beego.NSRouter("/logout", &AuthController{}, "*:Logout"),
			beego.NSRouter("/info", &UserController{}, "get:Info"),
			beego.NSRouter("/profile", &UserController{}, "get:ProfileGet;post:ProfilePost"),
			beego.NSRouter("/chpwd", &UserController{}, "*:ChangePassword"),
			beego.NSRouter("/users", &UserController{}, "get:Users"),
			beego.NSRouter("/user/c", &UserController{}, "get:CreateUserGet;post:CreateUserPost"),
			beego.NSRouter("/teams", &TeamController{}, "get:Teams"),
			beego.NSRouter("/team/c", &TeamController{}, "get:CreateTeamGet;post:CreateTeamPost"),
		)

	beego.AddNamespace(loginRequired)

	targetUserRequired :=
		beego.NewNamespace("/target-user",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetUser),
			beego.NSRouter("/delete", &UserController{}, "*:DeleteUser"),
			beego.NSRouter("/edit", &UserController{}, "get:EditGet;post:EditPost"),
			beego.NSRouter("/chpwd", &UserController{}, "post:ResetPassword"),
			beego.NSRouter("/role", &UserController{}, "*:Role"),
		)

	beego.AddNamespace(targetUserRequired)

	targetTeamRequired :=
		beego.NewNamespace("/target-team",
			beego.NSCond(func(ctx *context.Context) bool {
				return true
			}),
			beego.NSBefore(base.FilterLoginUser, base.FilterTargetTeam),
			beego.NSRouter("/delete", &TeamController{}, "*:DeleteTeam"),
			beego.NSRouter("/edit", &TeamController{}, "get:EditGet;post:EditPost"),
		)

	beego.AddNamespace(targetTeamRequired)

}