ServeHTTP satisfies the http.Handler interface, and is used to serve the root page of mtail for online status reporting.
(w http.ResponseWriter, _ *http.Request)
| 32 | // ServeHTTP satisfies the http.Handler interface, and is used to serve the |
| 33 | // root page of mtail for online status reporting. |
| 34 | func (m *Server) ServeHTTP(w http.ResponseWriter, _ *http.Request) { |
| 35 | t, err := template.New("status").Parse(statusTemplate) |
| 36 | if err != nil { |
| 37 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | te, err := template.New("statusend").Parse(statusTemplateEnd) |
| 42 | if err != nil { |
| 43 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | data := struct { |
| 48 | BindAddress string |
| 49 | BuildInfo string |
| 50 | HTTPDebugEndpoints bool |
| 51 | HTTPInfoEndpoints bool |
| 52 | }{ |
| 53 | m.listener.Addr().String(), |
| 54 | m.buildInfo.String(), |
| 55 | m.httpDebugEndpoints, |
| 56 | m.httpInfoEndpoints, |
| 57 | } |
| 58 | w.Header().Add("Content-type", "text/html") |
| 59 | w.WriteHeader(http.StatusOK) |
| 60 | if err = t.Execute(w, data); err != nil { |
| 61 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 62 | } |
| 63 | if m.httpInfoEndpoints { |
| 64 | err = m.r.WriteStatusHTML(w) |
| 65 | if err != nil { |
| 66 | glog.Warningf("Error while writing loader status: %s", err) |
| 67 | } |
| 68 | err = m.t.WriteStatusHTML(w) |
| 69 | if err != nil { |
| 70 | glog.Warningf("Error while writing tailer status: %s", err) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if err = te.Execute(w, data); err != nil { |
| 75 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // FaviconHandler is used to serve up the favicon.ico for mtail's http server. |
| 80 | func FaviconHandler(w http.ResponseWriter, _ *http.Request) { |
nothing calls this directly
no test coverage detected