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