Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Unified Diff: milo/frontend/routes.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: seems to work :) Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: milo/frontend/routes.go
diff --git a/milo/frontend/main.go b/milo/frontend/routes.go
similarity index 60%
rename from milo/frontend/main.go
rename to milo/frontend/routes.go
index 16a0899dfaaea33159c779c71465afc4dd3254da..7ae95fd3b94f715acdcb7c85c42a6349601d3809 100644
--- a/milo/frontend/main.go
+++ b/milo/frontend/routes.go
@@ -15,6 +15,7 @@
package frontend
import (
+ "fmt"
"net/http"
"github.com/golang/protobuf/proto"
@@ -24,15 +25,15 @@ import (
"github.com/luci/luci-go/grpc/discovery"
"github.com/luci/luci-go/grpc/grpcmon"
"github.com/luci/luci-go/grpc/prpc"
+ "github.com/luci/luci-go/server/router"
+
milo "github.com/luci/luci-go/milo/api/proto"
+ "github.com/luci/luci-go/milo/buildsource"
"github.com/luci/luci-go/milo/buildsource/buildbot"
"github.com/luci/luci-go/milo/buildsource/buildbucket"
"github.com/luci/luci-go/milo/buildsource/rawpresentation"
"github.com/luci/luci-go/milo/buildsource/swarming"
- "github.com/luci/luci-go/milo/common"
- "github.com/luci/luci-go/milo/frontend/console"
"github.com/luci/luci-go/milo/rpc"
- "github.com/luci/luci-go/server/router"
)
func emptyPrelude(c context.Context, methodName string, req proto.Message) (context.Context, error) {
@@ -45,7 +46,7 @@ func Run(templatePath string) {
r := router.New()
gaemiddleware.InstallHandlers(r)
- basemw := common.Base(templatePath)
+ basemw := base(templatePath)
r.GET("/", basemw, frontpageHandler)
// Admin and cron endpoints.
@@ -53,27 +54,57 @@ func Run(templatePath string) {
r.GET("/admin/configs", basemw, ConfigsHandler)
// Console
- r.GET("/console/:project/:name", basemw, console.ConsoleHandler)
- r.GET("/console/:project", basemw, console.Main)
+ r.GET("/console/:project/:name", basemw, ConsoleHandler)
+ r.GET("/console/:project", basemw, ConsoleMainHandler)
// Swarming
- r.GET(swarming.URLBase+"/:id/steps/*logname", basemw, swarming.LogHandler)
- r.GET(swarming.URLBase+"/:id", basemw, swarming.BuildHandler)
+ r.GET(swarming.URLBase+"/:id/steps/*logname", basemw, func(c *router.Context) {
Ryan Tseng 2017/07/13 22:00:47 I'm seeing some multi-line repetition, consider mo
iannucci 2017/07/14 19:00:23 I considered that, but I prefer this way, because
Ryan Tseng 2017/07/14 19:18:21 makes sense then. this is fine then. moving them
+ LogHandler(c, &swarming.BuildID{
+ TaskID: c.Params.ByName("id"),
+ }, c.Params.ByName("logname"))
+ })
+ r.GET(swarming.URLBase+"/:id", basemw, func(c *router.Context) {
+ BuildHandler(c, &swarming.BuildID{TaskID: c.Params.ByName("id")})
+ })
// Backward-compatible URLs for Swarming:
- r.GET("/swarming/prod/:id/steps/*logname", basemw, swarming.LogHandler)
- r.GET("/swarming/prod/:id", basemw, swarming.BuildHandler)
+ r.GET("/swarming/prod/:id/steps/*logname", basemw, func(c *router.Context) {
+ LogHandler(c, &swarming.BuildID{
+ TaskID: c.Params.ByName("id"),
+ }, c.Params.ByName("logname"))
+ })
+ r.GET("/swarming/prod/:id", basemw, func(c *router.Context) {
+ BuildHandler(c, &swarming.BuildID{TaskID: c.Params.ByName("id")})
+ })
// Buildbucket
- r.GET("/buildbucket/:bucket/:builder", basemw, buildbucket.BuilderHandler)
+ r.GET("/buildbucket/:bucket/:builder", basemw, func(c *router.Context) {
+ BuilderHandler(c, buildsource.BuilderID(
+ fmt.Sprintf("buildbucket/%s/%s", c.Params.ByName("bucket"), c.Params.ByName("builder"))))
+ })
// Buildbot
- r.GET("/buildbot/:master/:builder/:build", basemw, buildbot.BuildHandler)
- r.GET("/buildbot/:master/:builder/", basemw, buildbot.BuilderHandler)
+ r.GET("/buildbot/:master/:builder/:build", basemw, func(c *router.Context) {
+ BuildHandler(c, buildbot.NewBuildID(
+ c.Params.ByName("master"),
+ c.Params.ByName("builder"),
+ c.Params.ByName("build"),
+ ))
+ })
+ r.GET("/buildbot/:master/:builder/", basemw, func(c *router.Context) {
+ BuilderHandler(c, buildsource.BuilderID(
+ fmt.Sprintf("buildbot/%s/%s", c.Params.ByName("master"), c.Params.ByName("builder"))))
+ })
// LogDog Milo Annotation Streams.
// This mimicks the `logdog://logdog_host/project/*path` url scheme seen on
// swarming tasks.
- r.GET("/raw/build/:logdog_host/:project/*path", basemw, rawpresentation.BuildHandler)
+ r.GET("/raw/build/:logdog_host/:project/*path", basemw, func(c *router.Context) {
+ BuildHandler(c, rawpresentation.NewBuildID(
+ c.Params.ByName("logdog_host"),
+ c.Params.ByName("project"),
+ c.Params.ByName("path"),
+ ))
+ })
// PubSub subscription endpoints.
r.POST("/_ah/push-handlers/buildbot", basemw, buildbot.PubSubHandler)

Powered by Google App Engine
This is Rietveld 408576698