Golang Router示例

说明

golang router示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: github.com/astaxie/beego

示例#1
文件: router.go 项目: xxoommd/SimpleAccountSystem

// 自定义RESTful路由,并创建对应路径的静态文件路径以解决静态文件加载不正确的问题
func customRESTfulRouter(URLPath string, c beego.ControllerInterface) {
	beego.Router(URLPath, c, "get:Index;post:Create")
	beego.Router(URLPath+"/new", c, "get:New")
	beego.Router(URLPath+"/:id([0-9]+)", c, "get:Show;post:Update;Delete:Destroy")

	beego.SetStaticPath(URLPath+"/static", "static")
}

示例#2
文件: hello.go 项目: nathana1/FrameworkBenchmarks

func main() {
	beego.BConfig.RunMode = "prod"
	beego.Router("/json", &JsonController{})
	beego.Router("/db", &DBController{})
	beego.Router("/plaintext", &PlaintextController{})
	beego.Run()
}

示例#3
文件: router.go 项目: wcgh/beewechat

func init() {
	beego.Router("/", &controllers.WeChatController{})
	beego.Router("/home", &controllers.WeChatController{})

	// beego.Router("/test", &controllers.TestController{})
	// beego.Router("/b", &controllers.BController{})
}

示例#4
文件: router.go 项目: RoyburnsPeng/goTestLinkReport

func init() {

	// main
	beego.Router("/", &controllers.IndexController{})
	beego.Router("/plan", &controllers.PlanController{})

	// beego.Router("/report", &controllers.ReportController{})
	beego.Router("/getlastexecution", &controllers.GetLastExecutionController{})

	// Statistics
	// beego.Router("/statistics", &controllers.StatisticsController{})
	beego.Router("/statistics/sprint", &controllers.StatisticsController{})
	beego.Router("/api/statistics/sprint", &controllers.StatisticsController{}, "get:Sprint")
	// beego.Router("/api/statistics/stock", &controllers.StatisticsController{}, "get:Stock")

	// Test
	beego.Router("/test", &controllers.TestController{})

	// About
	beego.Router("/about", &controllers.AboutController{})

	// cmd
	// beego.Router("/cmd", &controllers.CmdController{})

	// api
	beego.Router("/api/getplan", &apis.ApiController{}, "get:GetPlan")
	beego.Router("/api/getlastexecution", &apis.ApiController{}, "get:GetLastExecution")
	beego.Router("/api/runcmd", &apis.ApiController{}, "get:RunCmd")

	// static file
	beego.SetStaticPath("/data", "data")
}

示例#5
文件: problem.go 项目: jango2015/ojsite

func Problem() {
	beego.Router("/problems", &problem.ProblemListController{})
	beego.Router("/problem/:title", &problem.ProblemDetailController{})
	beego.Router("/problem/add", &problem.AddProblemController{})
	beego.Router("/problem/submit", &problem.ProblemSubmitController{})
	beego.Router("/problem/submit/status", &problem.ProblemSubmitStatusController{})
}

示例#6
文件: posts.go 项目: xiaoyang2022/goBlog

func init() {
	beego.Router("/", &controllers.PostController{})
	//beego.Router("/post/:id:int", &controllers.PostController{}, "get:ShowOne")
	beego.Router("/list/:page:int", &controllers.PostController{}, "get:Get")
	beego.Router("/cate/:cid:int/:page:int", &controllers.PostController{}, "get:ListByCate")
	beego.Router("/month/:month/:page:int", &controllers.PostController{}, "get:ListByMonth")
}

示例#7
文件: router.go 项目: mjpeck/hudunwut

func init() {
	beego.SetStaticPath("/static", "public")

	beego.Router("/", &controllers.MainController{})

	beego.Router("/accounts/register", &controllers.RegistrationController{})
}

示例#8
文件: router.go 项目: kaituoay/TestApp

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/PartitionServer", &controllers.PartitionServer{}, "get:Profile")
	beego.Router("/api/PartitionServer", &controllers.PartitionServer{}, "get:API_Prof")
	//  beego.Router("rootpath",&controllers , ...)
	//将 域名的根目录映射给了 MainController方法
}

示例#9
文件: main.go 项目: allen870409/dcsolusion

func main() {
	beego.Router("/", &controllers.IndexController{}, "get:Get")
	beego.Router("/login/", &controllers.LoginController{}, "get:Get;post:Post")
	beego.Router("/logout/", &controllers.LogOutController{}, "get:Get")
	beego.Router("/admin", &controllers.AdminController{}, "get:Get")
	beego.Run(MyConfig.String("http_port"))
}

示例#10
文件: App.go 项目: elvizlai/Blog-mysql

func main() {
	beego.Debug(beego.VERSION)

	beego.Router("/test", &controllers.Test{})
	beego.Router("/upload", &controllers.Upload{})
	beego.Run()
}

示例#11
文件: main.go 项目: javazhen/blog

func main() {

	//初始化
	initialize()

	beego.Info(beego.AppName, APP_VER)

	if !controllers.IsPro {
		beego.SetStaticPath("/static_source", "static_source")
		beego.DirectoryIndex = true
	}

	// 开启 ORM 调试模式
	orm.Debug = true
	// 自动建表
	orm.RunSyncdb("default", false, true)

	beego.Router("/", &controllers.MainController{})
	beego.Router("/user/reg", &controllers.UserController{}, "post:reg")

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)

	beego.Run()
}

示例#12
文件: main.go 项目: cristian-sima/Wisply

func loadHelp() {
	beego.Router("/help", &public.Static{}, "*:ShowHelp")
	beego.Router("/privacy", &public.Static{}, "*:ShowPrivacyPolicy")
	beego.Router("/cookies", &public.Static{}, "*:ShowCookiesPolicy")
	beego.Router("/terms-and-conditions", &public.Static{}, "*:ShowTerms")
	beego.Router("/take-down-policy", &public.Static{}, "*:ShowTakeDownPolicy")
}

示例#13
文件: router.go 项目: royburns/goRemoteCMD

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/cmd", &controllers.CMDController{})
	beego.Router("/cmd/:name", &controllers.CMDController{})

	beego.RESTRouter("/object", &controllers.ObjectController{})
}

示例#14
文件: main.go 项目: zycbobby/remote-downloader

func main() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/tasks/?:taskId", &controllers.TaskController{})

	// read conf/app.conf automatically
	beego.Run()
}

示例#15
文件: router.go 项目: yakun0622/goblog

func init() {
	beego.Router("/", &controllers.MainController{})

	beego.Router("/user/profile", &controllers.UserController{}, `get:Profile`)

	beego.Router("/api/user/profile", &controllers.UserController{}, `get:API_Profile`)
}

示例#16
文件: beebbs.go 项目: sirithink/beebbs

func main() {
	initialize()

	beego.Info(beego.AppName, APP_VER)

	// Register routers.
	beego.Router("/", &routers.HomeRouter{})
	beego.Router("/login", &routers.LoginRouter{})

	beego.Router("/register", &routers.RegisterRouter{})
	beego.Router("/register/success", &routers.RegisterRouter{}, "get:Success")
	beego.Router("/active/success", &routers.RegisterRouter{}, "get:ActiveSuccess")
	beego.Router("/active/:code([0-9a-zA-Z]+)", &routers.RegisterRouter{}, "get:Active")
	beego.Router("/active/resend", &routers.RegisterRouter{}, "post:Resend")

	beego.Router("/forgot", &routers.ForgotRouter{})
	beego.Router("/reset", &routers.ResetRouter{})

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)

	// "robot.txt"
	beego.Router("/robot.txt", &routers.RobotRouter{})

	// For all unknown pages.
	beego.Run()
}

示例#17
文件: router.go 项目: kice/KiDanmaku

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("demo", &controllers.DemoController{})
	beego.Router("dmpost", &controllers.DanmakuPost{})
	beego.Router("dmget", &controllers.DanmakuGet{})

}

示例#18
文件: admin.go 项目: e154/www.novshin.ru

func init() {
	beego.Router("/admin", &controllers.Dashboard{}, "*:Index")
	beego.Router("/admin/login", &controllers.LoginController{}, "*:Login")
	beego.Router("/admin/logout", &controllers.LoginController{}, "*:Logout")
	beego.Router("/admin/recovery", &controllers.LoginController{}, "post:Recovery")
	beego.Router("/admin/reset", &controllers.ResetController{})
}

示例#19
文件: beeweb.go 项目: 858806258/beeweb

func main() {

	initialize()

	beego.Info(beego.AppName, APP_VER)

	beego.AddFilter("/docs/images/:all", "BeforeRouter", routers.DocsStatic)

	// Register routers.
	beego.Router("/", &routers.HomeRouter{})
	beego.Router("/community", &routers.CommunityRouter{})
	beego.Router("/quickstart", &routers.QuickStartRouter{})
	beego.Router("/team", &routers.PageRouter{})
	beego.Router("/about", &routers.AboutRouter{})
	beego.Router("/donate", &routers.DonateRouter{})
	beego.Router("/docs/", &routers.DocsRouter{})
	beego.Router("/docs/:all", &routers.DocsRouter{})
	beego.Router("/blog", &routers.BlogRouter{})
	beego.Router("/blog/:all", &routers.BlogRouter{})
	// beego.Router("/samples", &routers.SamplesRouter{})
	// beego.Router("/samples/:all", &routers.SamplesRouter{})

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)

	beego.Run()
}

示例#20
文件: main.go 项目: onuryilmaz/random-peek

// main starts the application
func main() {

	beego.ErrorController(&controllers.ErrorController{})
	beego.Router("/", &controllers.MainController{})
	beego.Router("/streams", &controllers.StreamController{})
	beego.Run()
}

示例#21
文件: gowalker.go 项目: juju2013/gowalker

func main() {
	initialize()
	go catchExit()

	beego.Info(beego.AppName, APP_VER)

	// Register routers.
	beego.Router("/", &routers.HomeRouter{})
	beego.Router("/refresh", &routers.RefreshRouter{})
	beego.Router("/search", &routers.SearchRouter{})
	beego.Router("/index", &routers.IndexRouter{})
	// beego.Router("/label", &routers.LabelsRouter{})
	beego.Router("/function", &routers.FuncsRouter{})
	beego.Router("/example", &routers.ExamplesRouter{})
	beego.Router("/about", &routers.AboutRouter{})

	beego.Router("/api/v1/badge", &routers.ApiRouter{}, "get:Badge")

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)
	beego.AddFuncMap("isHasEleS", isHasEleS)
	beego.AddFuncMap("isHasEleE", isHasEleE)
	beego.AddFuncMap("isNotEmptyS", isNotEmptyS)

	// "robot.txt"
	beego.Router("/robots.txt", &routers.RobotRouter{})

	// For all unknown pages.
	beego.Router("/:all", &routers.HomeRouter{})

	// Static path.
	beego.SetStaticPath("/public", "public")
	beego.Run()
}

示例#22
文件: router.go 项目: phillihq/beelike

func init() {
	//beego.Router("/", &controllers.MainController{})

	beego.Router("/", new(controllers.BuoyController), "get:Index")
	beego.Router("/buoy/retrievestation", new(controllers.BuoyController), "post:RetrieveStation")
	beego.Router("/buoy/station/:stationId", new(controllers.BuoyController), "get,post:RetrieveStationJSON")
}

示例#23
文件: router.go 项目: nizsheanez/ria

func init() {
	beego.Router("/", &user.MainController{})
	beego.Router("/user", &user.UserController{})
	beego.Router("/user/list", &user.UserController{}, "get:List")
	beego.Router("/article/", &article.ArticleController{})
	beego.Router("/article/list", &article.ArticleController{}, "get:List")
}

示例#24
文件: main.go 项目: jcs7575/push

func main() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/push/create", &controllers.IndexController{})
	beego.Router("/push/test", &controllers.TestController{})
	beego.Router("/push/query", &controllers.QueryController{})
	beego.Run()
}

示例#25
文件: router.go 项目: kevinxu001/goblog

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/category", &controllers.CategoryController{})
	beego.Router("/topic", &controllers.TopicController{})
	beego.AutoRouter(&controllers.TopicController{})
	beego.Router("/login", &controllers.LoginController{})
}

示例#26
文件: router.go 项目: ray0807/goAPI

func init() {
	// ns := beego.NewNamespace("/v1",
	// 	beego.NSNamespace("/object",
	// 		beego.NSInclude(
	// 			&controllers.ObjectController{},
	// 		),
	// 	),
	// 	beego.NSNamespace("/user",
	// 		beego.NSInclude(
	// 			&controllers.UserController{},
	// 		),
	// 	),
	// )
	beego.Router("/login", &controllers.LoginContriller{})
	beego.Router("/reg", &controllers.RegisterContriller{})
	beego.Router("/upload", &controllers.UploadContriller{})

	// WebSocket.
	beego.Router("/ws", &controllers.WebSocketController{})
	beego.Router("/ws/join", &controllers.WebSocketController{}, "get:Join")
	os.Mkdir("images", os.ModePerm)
	//set image static url
	beego.SetStaticPath("/images", "images")
	// beego.AddNamespace(ns)
}

示例#27
文件: router.go 项目: moonstudio/tucao

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/tucao", &controllers.MainController{})
	// 附件处理
	os.Mkdir("attachment", os.ModePerm)
	beego.Router("/attachment/:all", &controllers.AttachController{})
}

示例#28
文件: router.go 项目: 3xxx/UEditor-golang

func init() {
	beego.Router("/controller", &controllers.UeditorController{}, "*:ControllerUE")
	// beego.Router("/category", &controllers.CategoryController{}) //相当于get
	beego.Router("/category/add", &controllers.CategoryController{}, "get:Add")
	// beego.AutoRouter(&controllers.CategoryController{}) //这句代替上句也行
	beego.Router("/attachment/*", &controllers.AttachController{})
}

示例#29
文件: router.go 项目: qiangmzsx/golang

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.Router("/hello", &controllers.HelloController{})
	beego.Router("/admin", &admin.AdminController{})
	beego.Router("/admin/info", &admin.AdminController{}, "get:Info") //"*:Info"
	beego.AutoRouter(&controllers.AutoController{})
}

示例#30
文件: router.go 项目: zengcheng/sfs

func init() {
	beego.Router("/", &controllers.MainController{})
	beego.AutoRouter(&controllers.PointController{})
	beego.Router("/point/SavePoints", &controllers.PointController{}, "post:SavePoints")
	beego.Router("/point/GetTypeList", &controllers.PointController{}, "get:GetTypeList")
	beego.Router("/point/GetWeekPointsJson/:id", &controllers.PointController{}, "get:GetWeekPointsJson")
}

展开阅读全文