aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/api/api.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-10-05 17:54:56 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-10-05 17:54:56 -0400
commit424355dfb6c65e688057619a694542abd4623115 (patch)
treed390619dcd900286cf18a04a4976b82ca4221992 /api/api.go
parent6c4f55aa3521af4fc5343b8412c2aed3e047008e (diff)
Add endpoint for foundry container's logs
Diffstat (limited to 'api/api.go')
-rw-r--r--api/api.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/api/api.go b/api/api.go
index c74723d..957651e 100644
--- a/api/api.go
+++ b/api/api.go
@@ -3,9 +3,11 @@ package api
import (
"context"
"encoding/json"
+ "io"
"log/slog"
"net/http"
"os"
+ "strconv"
"time"
)
@@ -40,7 +42,7 @@ func respondOnline(w http.ResponseWriter, status ServerStatus) {
jsonData, err := json.Marshal(status)
if err != nil {
http.Error(w, "Error constructing response", http.StatusInternalServerError)
- Logger.Error("Error marshalling site status data")
+ Logger.Error("Error marshalling site status data", slog.Any("err", err))
return
}
@@ -61,6 +63,31 @@ func VttRedirect(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req, VTT_URL, http.StatusMovedPermanently)
}
+func VttLogs(w http.ResponseWriter, req *http.Request) {
+ var lines uint = 0
+
+ linesParam := req.URL.Query().Get("lines")
+ if linesParam != "" {
+ lines_64, err := strconv.ParseUint(linesParam, 10, 64)
+ if err != nil {
+ Logger.ErrorContext(req.Context(), "Invalid line count in vtt logs request", slog.Any("err", err))
+ http.Error(w, "Invalid line count in request", http.StatusBadRequest)
+ return
+ }
+
+ lines = uint(lines_64)
+ }
+
+ logReader, err := vttLogs(req.Context(), lines)
+ if err != nil {
+ http.Error(w, "Error occured while getting logs", http.StatusInternalServerError)
+ return
+ }
+ defer logReader.Close()
+
+ io.Copy(w, logReader)
+}
+
func SiteOnline(w http.ResponseWriter, req *http.Request) {
const URL string = "https://dnd.jpappel.xyz"