added dynamic hostname to helpHandler
All checks were successful
/ push_to_registry (push) Successful in 51s
All checks were successful
/ push_to_registry (push) Successful in 51s
This commit is contained in:
159
main.go
159
main.go
@@ -46,82 +46,95 @@ 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>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hilfe</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
.help-container {
|
||||
text-align: left;
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 800px;
|
||||
width: 90%;
|
||||
min-width: 500px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: #444;
|
||||
}
|
||||
pre {
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 0.8rem;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
a {
|
||||
color: #007BFF;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="help-container">
|
||||
<h1>Hilfe: API-Endpunkt</h1>
|
||||
<p>
|
||||
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen.
|
||||
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
|
||||
</p>
|
||||
<h2>Endpunkt:</h2>
|
||||
<p><code>http://localhost:8080/api/password</code></p>
|
||||
<h2>Beispiele:</h2>
|
||||
<h3>Mac/Linux (Terminal):</h3>
|
||||
<pre>echo $(curl -s http://localhost:8080/api/password)</pre>
|
||||
<h3>Windows (PowerShell):</h3>
|
||||
<pre>Invoke-RestMethod -Uri http://localhost:8080/api/password</pre>
|
||||
<h3>Windows (cmd):</h3>
|
||||
<pre>curl http://localhost:8080/api/password</pre>
|
||||
<p>
|
||||
<a href="/">Zurück zur Passwort-Generierung</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, helpHTML)
|
||||
helpHTML := `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hilfe</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
.help-container {
|
||||
text-align: left;
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 800px;
|
||||
width: 90%;
|
||||
min-width: 500px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: #444;
|
||||
}
|
||||
pre {
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 0.8rem;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
a {
|
||||
color: #007BFF;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="help-container">
|
||||
<h1>Hilfe: API-Endpunkt</h1>
|
||||
<p>
|
||||
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen.
|
||||
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
|
||||
</p>
|
||||
<h2>Endpunkt:</h2>
|
||||
<p><code id="api-endpoint"></code></p>
|
||||
<h2>Beispiele:</h2>
|
||||
<h3>Mac/Linux (Terminal):</h3>
|
||||
<pre id="curl-example"></pre>
|
||||
<h3>Windows (PowerShell):</h3>
|
||||
<pre id="powershell-example"></pre>
|
||||
<h3>Windows (cmd):</h3>
|
||||
<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>
|
||||
`
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, helpHTML)
|
||||
}
|
||||
|
||||
|
||||
func webHandler(w http.ResponseWriter, r *http.Request) {
|
||||
password := generatePassword()
|
||||
html := fmt.Sprintf(
|
||||
|
||||
Reference in New Issue
Block a user