add json download on submit and improve styling

This commit is contained in:
Patryk Hegenberg 2023-11-24 22:35:09 +01:00
parent bd3b2817f2
commit 03040648f4
2 changed files with 14 additions and 3 deletions

View file

@ -13,7 +13,7 @@
justify-content: center;
min-height: 100vh;
margin: 0;
font-family: 'Arial', sans-serif;
font-family: 'arial', sans-serif;
transition: background-color 0.3s, color 0.3s;
}
@ -33,6 +33,8 @@
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: baseline;
padding: 10px;
}
.form-item2 {
@ -176,6 +178,7 @@
<label for="actionEntry">Action Entry:</label>
<input type="text" name="actionEntry" required class="input input-bordered w-full max-w-xs"><br>
</div>
<input type="hidden" name="filename" value="{{.Filename}}">
<div class="form-item2">
<input type="submit" value="Submit" class="btn">
</div>

12
main.go
View file

@ -214,9 +214,17 @@ func submitHandler(filename string) http.HandlerFunc {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Dateiinhalt lesen
fileContent, err := os.ReadFile(filename)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Erfolgsmeldung anzeigen
fmt.Fprintf(w, "Monsterdaten erfolgreich gespeichert in %s: %s", filename, charJSON)
// Datei zum Download anbieten
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filename))
w.Header().Set("Content-Type", "application/json")
w.Write(fileContent)
}
}