From 866a7a8b81f6d6aa4b62872590b76e63436990e2 Mon Sep 17 00:00:00 2001 From: structix Date: Mon, 12 Oct 2020 00:16:23 +0200 Subject: [PATCH] Add log buffer site --- database/admin.go | 5 ++++ handler/admin.go | 7 ++++++ html/admin/adminlogs.html | 34 ++++++++++++++++++++++++++++ html/static/navbaradmin.html | 1 + logbuffer/logbuffer.go | 33 +++++++++++++++++++++++++++ logbuffer/queue.go | 44 ++++++++++++++++++++++++++++++++++++ main.go | 8 ++++++- routes/routes.go | 4 +++- 8 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 html/admin/adminlogs.html create mode 100644 logbuffer/logbuffer.go create mode 100644 logbuffer/queue.go diff --git a/database/admin.go b/database/admin.go index 7dedcd1..6c03979 100644 --- a/database/admin.go +++ b/database/admin.go @@ -6,6 +6,7 @@ import ( "github.com/jackc/pgx/v4/pgxpool" "log" "strconv" + "trikotwaschliste/logbuffer" "trikotwaschliste/models" ) @@ -61,3 +62,7 @@ func ChangeName(pool *pgxpool.Pool, id, personID string) bool { return true } + +func Logs(queue *logbuffer.Queue) gin.H { + return gin.H{"items": queue.ToSlice()} +} \ No newline at end of file diff --git a/handler/admin.go b/handler/admin.go index b6e2ca7..0a972c8 100644 --- a/handler/admin.go +++ b/handler/admin.go @@ -5,6 +5,7 @@ import ( "github.com/jackc/pgx/v4/pgxpool" "net/http" "trikotwaschliste/database" + "trikotwaschliste/logbuffer" ) func AdminMainPage(pool *pgxpool.Pool) gin.HandlerFunc { @@ -22,3 +23,9 @@ func ChangeName(pool *pgxpool.Pool) gin.HandlerFunc { c.Redirect(302, "/admin") } } + +func Logs(queue *logbuffer.Queue) gin.HandlerFunc { + return func(c *gin.Context) { + c.HTML(http.StatusAccepted, "adminlogs.html", database.Logs(queue)) + } +} \ No newline at end of file diff --git a/html/admin/adminlogs.html b/html/admin/adminlogs.html new file mode 100644 index 0000000..8b9fdfe --- /dev/null +++ b/html/admin/adminlogs.html @@ -0,0 +1,34 @@ + + + + + Trikotwaschliste - Admin + + + + + +{{template "navbaradmin"}} +
+

Logs AdminDie letzten 50 Einträge

+ + + + + + + + {{range .items}} + + + + {{end}} + +
Logs
+ {{.}} +
+ +
+ + + \ No newline at end of file diff --git a/html/static/navbaradmin.html b/html/static/navbaradmin.html index dc51231..fc92a6e 100644 --- a/html/static/navbaradmin.html +++ b/html/static/navbaradmin.html @@ -1,6 +1,7 @@ {{define "navbaradmin"}}