format code with gofmt
This commit is contained in:
parent
f3432ce106
commit
08814b0e82
1 changed files with 47 additions and 47 deletions
94
go/main.go
Executable file → Normal file
94
go/main.go
Executable file → Normal file
|
@ -21,32 +21,32 @@ var (
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", homeHandler)
|
http.HandleFunc("/", homeHandler)
|
||||||
http.HandleFunc("/upload", uploadHandler)
|
http.HandleFunc("/upload", uploadHandler)
|
||||||
http.HandleFunc("/view/", viewHandler)
|
http.HandleFunc("/view/", viewHandler)
|
||||||
|
|
||||||
fmt.Println("Server listening on :8080")
|
fmt.Println("Server listening on :8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Setzen der Content Security Policy
|
// Setzen der Content Security Policy
|
||||||
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")
|
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")
|
||||||
|
|
||||||
// Verwenden von html/template zur sicheren Ausgabe von HTML
|
// Verwenden von html/template zur sicheren Ausgabe von HTML
|
||||||
tmpl, err := template.ParseFiles("templates/homeTemplate.html")
|
tmpl, err := template.ParseFiles("templates/homeTemplate.html")
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data := struct {
|
|
||||||
Title string
|
|
||||||
}{
|
|
||||||
Title: "Bildupload",
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := struct {
|
||||||
|
Title string
|
||||||
|
}{
|
||||||
|
Title: "Bildupload",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tmpl.Execute(w, data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,43 +113,43 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
lastUploadTime = time.Now() // Setzen Sie die Zeit des letzten Uploads
|
lastUploadTime = time.Now() // Setzen Sie die Zeit des letzten Uploads
|
||||||
|
|
||||||
// Nach erfolgreichem Upload:
|
// Nach erfolgreichem Upload:
|
||||||
tmpl, err := template.ParseFiles("templates/uploadSuccess.html")
|
tmpl, err := template.ParseFiles("templates/uploadSuccess.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||||
log.Printf("Fehler beim Laden des Templates: %v", err)
|
log.Printf("Fehler beim Laden des Templates: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Message string
|
Message string
|
||||||
Filename string
|
Filename string
|
||||||
}{
|
}{
|
||||||
Message: "Bild erfolgreich hochgeladen.",
|
Message: "Bild erfolgreich hochgeladen.",
|
||||||
Filename: handler.Filename,
|
Filename: handler.Filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
||||||
log.Printf("Fehler beim Rendern des Templates: %v", err)
|
log.Printf("Fehler beim Rendern des Templates: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("templates/uploadForm.html")
|
tmpl, err := template.ParseFiles("templates/uploadForm.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||||
log.Printf("Fehler beim Laden des Templates: %v", err)
|
log.Printf("Fehler beim Laden des Templates: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, nil)
|
err = tmpl.Execute(w, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Rendern des Templates", http.StatusInternalServerError)
|
||||||
log.Printf("Fehler beim Rendern des Templates: %v", err)
|
log.Printf("Fehler beim Rendern des Templates: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue