indexHandler handles requests to the server for the root location "/". A listing of the attached devices is obtained and applied to the index.html template response. An error page is returned if an error occurred.
(w http.ResponseWriter, r *http.Request)
| 122 | // A listing of the attached devices is obtained and applied to the index.html template response. |
| 123 | // An error page is returned if an error occurred. |
| 124 | func indexHandler(w http.ResponseWriter, r *http.Request) { |
| 125 | cmd := exec.Command("lsblk", "--nodeps") |
| 126 | stdout, err := cmd.Output() |
| 127 | if err != nil { |
| 128 | errorPage(w, err); |
| 129 | } |
| 130 | |
| 131 | p := &IndexPage{Lsblk: stdout} |
| 132 | t, _ := template.ParseFiles("./templates/index.html") |
| 133 | t.Execute(w, p) |
| 134 | } |
| 135 | |
| 136 | // errorPage returns an HTML error page, inserting error details into the error.html template. |
| 137 | func errorPage(w http.ResponseWriter, err error) { |
nothing calls this directly
no test coverage detected