Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status page that shows recent commands
Recent commands are stored in memory. They're not persisted to any database, so the log is gone if the instance dies. It's sufficient for my needs though.
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
|
||
"github.com/mtraver/gaelog" | ||
) | ||
|
||
type statusHandler struct { | ||
Template *template.Template | ||
} | ||
|
||
func (h statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
lg, err := gaelog.New(r) | ||
if err != nil { | ||
lg.Errorf("%v", err) | ||
} | ||
defer lg.Close() | ||
|
||
actionLogMux.Lock() | ||
defer actionLogMux.Unlock() | ||
|
||
if err := h.Template.ExecuteTemplate(w, "status", actionLog); err != nil { | ||
lg.Errorf("Could not execute template: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{ define "status" }} | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>RPi IR Remote | Status</title> | ||
</head> | ||
<body> | ||
<ul> | ||
{{ range $record := . }} | ||
<li>{{ if $record.Success }}OK{{ else }}FAIL{{ end }} | {{ RFC3339 $record.Timestamp }} | {{ $record.Action }}</li> | ||
{{ end }} | ||
</ul> | ||
</body> | ||
</html> | ||
{{ end }} |