Vary title for executable

This commit is contained in:
Josh Deprez 2024-04-26 09:38:00 +10:00
parent 2d8897768b
commit 15621ec7e0
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
3 changed files with 14 additions and 4 deletions

View file

@ -14,6 +14,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/user" "os/user"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
@ -38,8 +39,14 @@ var (
} }
return fmt.Sprintf("%s (uid=%s)", user.Username, user.Uid) return fmt.Sprintf("%s (uid=%s)", user.Username, user.Uid)
}() }()
exepath, _ = os.Executable() exepath, exename = func() (string, string) {
startTime = time.Now() exe, _ := os.Executable()
if exe == "" {
return "(unknown)", "(unknown)"
}
return exe, filepath.Base(exe)
}()
startTime = time.Now()
rootItem = &simpleItem{ rootItem = &simpleItem{
baseItem: baseItem{ baseItem: baseItem{
@ -63,6 +70,7 @@ type statusData struct {
Build string Build string
Hostname string Hostname string
Username string Username string
ExeName string
ExePath string ExePath string
PID int PID int
Compiler string Compiler string
@ -191,6 +199,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
Build: "TODO", Build: "TODO",
Hostname: hostname, Hostname: hostname,
Username: username, Username: username,
ExeName: exename,
ExePath: exepath, ExePath: exepath,
PID: os.Getpid(), PID: os.Getpid(),
Compiler: runtime.Compiler, Compiler: runtime.Compiler,

View file

@ -10,7 +10,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Status</title> <title>Status for {{.ExeName}}</title>
<style> <style>
body { body {
font-family: sans-serif; font-family: sans-serif;
@ -62,7 +62,7 @@
</style> </style>
</head> </head>
<body> <body>
<h1>Status</h1> <h1>Status for {{.ExeName}}</h1>
<div class="summary"> <div class="summary">
{{.ExePath}}<br> {{.ExePath}}<br>
Started at {{.StartTime}} ({{.StartTimeAgo}} ago)<br> Started at {{.StartTime}} ({{.StartTimeAgo}} ago)<br>

View file

@ -47,6 +47,7 @@ func TestSmokeStatusTemplate(t *testing.T) {
Build: "1234", Build: "1234",
Hostname: hostname, Hostname: hostname,
Username: username, Username: username,
ExeName: exename,
ExePath: exepath, ExePath: exepath,
PID: os.Getpid(), PID: os.Getpid(),
Compiler: runtime.Compiler, Compiler: runtime.Compiler,