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

Side by Side Diff: milo/appengine/logs/main.go

Issue 2796743004: Milo flex raw log viewer endpoint (Closed)
Patch Set: Fix module path Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "fmt"
9 "log"
10 "net/http"
11 "strings"
12
13 "github.com/luci/luci-go/milo/appengine/common"
14 "github.com/luci/luci-go/server/auth"
15 "github.com/luci/luci-go/server/router"
16 )
17
18 // Where it all begins!!!
19 func main() {
20 r := router.New()
21
22 base := common.FlexBase()
23 r.GET("/log/raw/*path", base, rawLog)
24
25 // Health check, for the appengine flex environment.
26 http.HandleFunc("/_ah/health", healthCheckHandler)
27 // And everything else.
28 http.Handle("/", r)
29
30 log.Print("Listening on port 8080")
31 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
32 }
33
34 func errorPage(c *router.Context, msg string) {
35 c.Writer.WriteHeader(http.StatusInternalServerError)
36 fmt.Fprintf(c.Writer, msg)
37 }
38
39 func rawLog(c *router.Context) {
40 path := c.Params.ByName("path")
41 if path == "" {
42 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.
43 return
44 }
45 path = strings.TrimLeft(path, "/")
46 host := c.Request.FormValue("host")
47 if host == "" {
48 host = "luci-logdog.appspot.com"
49 }
50 err := logHandler(c.Context, c.Writer, host, path)
51 switch err {
52 case nil:
53 // Everything is fine
54 case errNoAuth:
55 // Redirect to login page
56 loginURL, err := auth.LoginURL(c.Context, c.Request.URL.Path)
57 if err != nil {
58 fmt.Fprintf(c.Writer, "Encountered error generating logi n url: %s\n", err.Error())
59 return
60 }
61 http.Redirect(c.Writer, c.Request, loginURL, http.StatusTemporar yRedirect)
62 return
63 default:
64 fmt.Fprintf(c.Writer, "Encountered error: %s", err.Error())
65 }
66 }
67
68 func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
69 fmt.Fprint(w, "ok")
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698