Chromium Code Reviews| Index: milo/appengine/logs/main.go |
| diff --git a/milo/appengine/logs/main.go b/milo/appengine/logs/main.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f066cee285922ed6cbf00216ccf51532cdb08591 |
| --- /dev/null |
| +++ b/milo/appengine/logs/main.go |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2017 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package main |
| + |
| +import ( |
| + "fmt" |
| + "log" |
| + "net/http" |
| + "strings" |
| + |
| + "github.com/luci/luci-go/milo/appengine/common" |
| + "github.com/luci/luci-go/server/auth" |
| + "github.com/luci/luci-go/server/router" |
| +) |
| + |
| +// Where it all begins!!! |
| +func main() { |
| + r := router.New() |
| + |
| + base := common.FlexBase() |
| + r.GET("/log/raw/*path", base, rawLog) |
| + |
| + // Health check, for the appengine flex environment. |
| + http.HandleFunc("/_ah/health", healthCheckHandler) |
| + // And everything else. |
| + http.Handle("/", r) |
| + |
| + log.Print("Listening on port 8080") |
| + log.Fatal(http.ListenAndServe(":8080", nil)) |
|
nodir
2017/04/29 00:59:45
why are we unconditionally failing?
i think this s
hinoka
2017/05/01 23:08:03
This was how the sample code did it for the appeni
|
| +} |
| + |
| +func errorPage(c *router.Context, msg string) { |
| + c.Writer.WriteHeader(http.StatusInternalServerError) |
| + fmt.Fprintf(c.Writer, msg) |
| +} |
| + |
| +func rawLog(c *router.Context) { |
| + path := c.Params.ByName("path") |
| + if path == "" { |
| + errorPage(c, "missing path") |
|
nodir
2017/04/29 00:59:45
this should be http 400, not 500
hinoka
2017/05/01 23:08:03
Done.
|
| + return |
| + } |
| + path = strings.TrimLeft(path, "/") |
| + host := c.Request.FormValue("host") |
| + if host == "" { |
| + host = "luci-logdog.appspot.com" |
| + } |
| + err := logHandler(c.Context, c.Writer, host, path) |
| + switch err { |
| + case nil: |
| + // Everything is fine |
| + case errNoAuth: |
| + // Redirect to login page |
| + loginURL, err := auth.LoginURL(c.Context, c.Request.URL.Path) |
| + if err != nil { |
| + fmt.Fprintf(c.Writer, "Encountered error generating login url: %s\n", err.Error()) |
| + return |
| + } |
| + http.Redirect(c.Writer, c.Request, loginURL, http.StatusTemporaryRedirect) |
| + return |
| + default: |
| + fmt.Fprintf(c.Writer, "Encountered error: %s", err.Error()) |
| + } |
| +} |
| + |
| +func healthCheckHandler(w http.ResponseWriter, r *http.Request) { |
| + fmt.Fprint(w, "ok") |
| +} |