added dynamic hostname to helpHandler
All checks were successful
/ push_to_registry (push) Successful in 51s

This commit is contained in:
2026-01-17 21:59:54 +01:00
parent 36ce60aa28
commit 0a3f4ab5ef

21
main.go
View File

@@ -46,6 +46,7 @@ func passwordHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, password)
}
// new help handler
func helpHandler(w http.ResponseWriter, r *http.Request) {
helpHTML := `
<!DOCTYPE html>
@@ -103,18 +104,29 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
</p>
<h2>Endpunkt:</h2>
<p><code>http://localhost:8080/api/password</code></p>
<p><code id="api-endpoint"></code></p>
<h2>Beispiele:</h2>
<h3>Mac/Linux (Terminal):</h3>
<pre>echo $(curl -s http://localhost:8080/api/password)</pre>
<pre id="curl-example"></pre>
<h3>Windows (PowerShell):</h3>
<pre>Invoke-RestMethod -Uri http://localhost:8080/api/password</pre>
<pre id="powershell-example"></pre>
<h3>Windows (cmd):</h3>
<pre>curl http://localhost:8080/api/password</pre>
<pre id="cmd-example"></pre>
<p>
<a href="/">Zurück zur Passwort-Generierung</a>
</p>
</div>
<script>
// Dynamisch den aktuellen Hostnamen ermitteln
const currentHost = window.location.host;
const apiEndpoint = "http://" + currentHost + "/api/password";
// Hostnamen in die Beispiele eintragen
document.getElementById("api-endpoint").textContent = apiEndpoint;
document.getElementById("curl-example").textContent = "curl " + apiEndpoint;
document.getElementById("powershell-example").textContent = "Invoke-RestMethod -Uri " + apiEndpoint;
document.getElementById("cmd-example").textContent = "curl " + apiEndpoint;
</script>
</body>
</html>
`
@@ -122,6 +134,7 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, helpHTML)
}
func webHandler(w http.ResponseWriter, r *http.Request) {
password := generatePassword()
html := fmt.Sprintf(