add json download on submit and improve styling
This commit is contained in:
parent
bd3b2817f2
commit
03040648f4
2 changed files with 14 additions and 3 deletions
|
|
@ -13,7 +13,7 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: 'Arial', sans-serif;
|
font-family: 'arial', sans-serif;
|
||||||
transition: background-color 0.3s, color 0.3s;
|
transition: background-color 0.3s, color 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,6 +33,8 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-item2 {
|
.form-item2 {
|
||||||
|
|
@ -176,6 +178,7 @@
|
||||||
<label for="actionEntry">Action Entry:</label>
|
<label for="actionEntry">Action Entry:</label>
|
||||||
<input type="text" name="actionEntry" required class="input input-bordered w-full max-w-xs"><br>
|
<input type="text" name="actionEntry" required class="input input-bordered w-full max-w-xs"><br>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" name="filename" value="{{.Filename}}">
|
||||||
<div class="form-item2">
|
<div class="form-item2">
|
||||||
<input type="submit" value="Submit" class="btn">
|
<input type="submit" value="Submit" class="btn">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -214,9 +214,17 @@ func submitHandler(filename string) http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Dateiinhalt lesen
|
||||||
|
fileContent, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Erfolgsmeldung anzeigen
|
// Datei zum Download anbieten
|
||||||
fmt.Fprintf(w, "Monsterdaten erfolgreich gespeichert in %s: %s", filename, charJSON)
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filename))
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(fileContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue