1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00

Add menu with shutdown button

This commit is contained in:
nxshock 2022-03-26 16:44:46 +05:00
parent 970ce3bdae
commit 5d77188c05
2 changed files with 54 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/http" "net/http"
"os"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -11,6 +12,7 @@ import (
func httpServer(listenAddress string) { func httpServer(listenAddress string) {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
http.HandleFunc("/shutdown", handleShutdown)
http.HandleFunc("/start", handleForceStart) http.HandleFunc("/start", handleForceStart)
log.WithField("job", "http_server").Fatal(http.ListenAndServe(listenAddress, nil)) log.WithField("job", "http_server").Fatal(http.ListenAndServe(listenAddress, nil))
} }
@ -56,3 +58,14 @@ func handleForceStart(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("there is no job with name %s", jobName), http.StatusBadRequest) http.Error(w, fmt.Sprintf("there is no job with name %s", jobName), http.StatusBadRequest)
} }
func handleShutdown(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Application terminated.\n"))
go func() {
time.Sleep(time.Second)
log.WithField("job", "http_server").Infoln("Shutdown requested")
os.Exit(0)
}()
}

View File

@ -65,7 +65,7 @@
} }
th { th {
background-color: var(--base02); background-color: var(--base01);
} }
td, td,
@ -74,7 +74,7 @@
padding: 0.25em; padding: 0.25em;
} }
button { table button {
width: 100%; width: 100%;
color: #fff; color: #fff;
background-color: var(--base01); background-color: var(--base01);
@ -99,11 +99,50 @@
.runningbg { .runningbg {
background-color: var(--base0B); background-color: var(--base0B);
} }
.dropbtn {
background-color: var(--base01);
color: var(--base05);
padding: 0.5em;
cursor: pointer;
border: 0;
}
.dropdown {
position: relative;
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: var(--base01);
z-index: 1;
}
.dropdown-content a {
color: var(--base05);
padding: 0.5em;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style> </style>
</head> </head>
<body> <body>
<main> <main>
<div class="dropdown">
<button class="dropbtn">☰ Menu</button>
<div class="dropdown-content">
<a href="/shutdown">Shutdown</a>
</div>
</div>
<h1>Job list</h1> <h1>Job list</h1>
<table> <table>
<tr> <tr>