forked from WEB-IMB-WS2526/lab-development-imb
09: Lösungen
parent
5ac5953325
commit
74590780fc
|
|
@ -0,0 +1,5 @@
|
||||||
|
module uebung04
|
||||||
|
|
||||||
|
go 1.24.5
|
||||||
|
|
||||||
|
require github.com/lib/pq v1.10.9
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func insertToDB(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Nur POST-Methode erlaubt.", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Fehler beim Parsen des Formulars", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.PostForm) == 0 {
|
||||||
|
http.Error(w, "Kein POST-Formular gesendet", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
name := r.PostForm.Get("name")
|
||||||
|
hobbies := r.PostForm["hobby"]
|
||||||
|
// Umwandlung in einen String mit Komma-Trennung
|
||||||
|
hobbiesAsString := strings.Join(hobbies, ", ")
|
||||||
|
alter, err := strconv.Atoi(r.PostForm.Get("alter"))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Parameter konnte nicht korrekt verarbeitet werden:", err)
|
||||||
|
http.Error(w, "Benutzereingabe fehlerhaft.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verbindungszeichenfolge: Benutzername, Passwort, DB-Name, Host, Port
|
||||||
|
connStr := "user=devuser password=devpass dbname=devdb host=localhost port=5432 sslmode=disable"
|
||||||
|
|
||||||
|
// Verbindung zur Datenbank öffnen
|
||||||
|
db, err := sql.Open("postgres", connStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Öffnen der Verbindung:", err)
|
||||||
|
http.Error(w, "Interner Server-Fehler.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// Verbindung testen
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Datenbank nicht erreichbar:", err)
|
||||||
|
http.Error(w, "Interner Server-Fehler.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Verbindung erfolgreich hergestellt.")
|
||||||
|
|
||||||
|
// INSERT-Anweisung vorbereiten
|
||||||
|
query := `INSERT INTO personen (name, hobbies, alter) VALUES ($1, $2, $3)`
|
||||||
|
// INSERT-Anweisung ausführen
|
||||||
|
_, err = db.Exec(query, name, hobbiesAsString, alter)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Einfügen:", err)
|
||||||
|
http.Error(w, "Datensatz konnte nicht gespeichert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Datensatz erfolgreich eingefügt.")
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "Ihre Hobbies wurden erfolgreich gespeichert.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateInDB(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Nur POST-Methode erlaubt.", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Fehler beim Parsen des Formulars", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.PostForm) == 0 {
|
||||||
|
http.Error(w, "Kein POST-Formular gesendet", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
name := r.PostForm.Get("name")
|
||||||
|
hobbies := r.PostForm["hobby"]
|
||||||
|
// Umwandlung in einen String mit Komma-Trennung
|
||||||
|
hobbiesAsString := strings.Join(hobbies, ", ")
|
||||||
|
alter, err := strconv.Atoi(r.PostForm.Get("alter"))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Parameter konnte nicht korrekt verarbeitet werden:", err)
|
||||||
|
http.Error(w, "Benutzereingabe fehlerhaft.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verbindungszeichenfolge: Benutzername, Passwort, DB-Name, Host, Port
|
||||||
|
connStr := "user=devuser password=devpass dbname=devdb host=localhost port=5432 sslmode=disable"
|
||||||
|
|
||||||
|
// Verbindung zur Datenbank öffnen
|
||||||
|
db, err := sql.Open("postgres", connStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Öffnen der Verbindung:", err)
|
||||||
|
http.Error(w, "Interner Server-Fehler.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// Verbindung testen
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Datenbank nicht erreichbar:", err)
|
||||||
|
http.Error(w, "Interner Server-Fehler.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Verbindung erfolgreich hergestellt.")
|
||||||
|
|
||||||
|
// UPDATE-Anweisung vorbereiten
|
||||||
|
query := `UPDATE personen SET hobbies = $1, alter = $2 WHERE name = $3`
|
||||||
|
// UPDATE-Anweisung ausführen
|
||||||
|
_, err = db.Exec(query, hobbiesAsString, alter, name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Aktualisieren:", err)
|
||||||
|
http.Error(w, "Datensatz konnte nicht aktualisiert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Datensatz erfolgreich aktualisiert.")
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "Ihre Hobbies wurden erfolgreich aktualisiert.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/insert", insertToDB)
|
||||||
|
http.HandleFunc("/update", updateInDB)
|
||||||
|
fmt.Println("Server läuft auf localhost:8080...")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
module labor09/uebung0102
|
||||||
|
|
||||||
|
go 1.24.5
|
||||||
|
|
||||||
|
require github.com/lib/pq v1.10.9
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
var db *sql.DB
|
||||||
|
|
||||||
|
type dataManipulator func(w http.ResponseWriter, name string, hobbies string, alter int, db *sql.DB)
|
||||||
|
|
||||||
|
func insertToDB(w http.ResponseWriter, name string, hobbies string, alter int, db *sql.DB) {
|
||||||
|
|
||||||
|
// INSERT-Anweisung vorbereiten
|
||||||
|
query := `INSERT INTO personen (name, hobbies, alter) VALUES ($1, $2, $3)`
|
||||||
|
// INSERT-Anweisung ausführen
|
||||||
|
_, err := db.Exec(query, name, hobbies, alter)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Einfügen:", err)
|
||||||
|
http.Error(w, "Datensatz konnte nicht gespeichert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Datensatz erfolgreich eingefügt.")
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "Ihre Hobbies wurden erfolgreich gespeichert.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateInDB(w http.ResponseWriter, name string, hobbies string, alter int, db *sql.DB) {
|
||||||
|
|
||||||
|
// UPDATE-Anweisung vorbereiten
|
||||||
|
query := `UPDATE personen SET hobbies = $1, alter =$2 WHERE name = $3`
|
||||||
|
// UPDATE-Anweisung ausführen
|
||||||
|
_, err := db.Exec(query, hobbies, alter, name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Fehler beim Aktualisieren:", err)
|
||||||
|
http.Error(w, "Datensatz konnte nicht aktualisiert werden.", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Datensatz erfolgreich aktualisiert.")
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "Ihre Hobbies wurden erfolgreich aktualisiert.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleFormRequest(w http.ResponseWriter, r *http.Request, dbf dataManipulator) {
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Nur POST-Methode erlaubt.", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Fehler beim Parsen des Formulars", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.PostForm) == 0 {
|
||||||
|
http.Error(w, "Kein POST-Formular gesendet", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
name := r.PostForm.Get("name")
|
||||||
|
hobbies := r.PostForm["hobby"]
|
||||||
|
// Umwandlung in einen String mit Komma-Trennung
|
||||||
|
hobbiesAsString := strings.Join(hobbies, ", ")
|
||||||
|
alter, err := strconv.Atoi(r.PostForm.Get("alter"))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Parameter konnte nicht korrekt verarbeitet werden:", err)
|
||||||
|
http.Error(w, "Benutzereingabe fehlerhaft.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dbf(w, name, hobbiesAsString, alter, db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleFormRequestWithDB(dbm dataManipulator) func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) { handleFormRequest(w, r, dbm) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Verbindungszeichenfolge: Benutzername, Passwort, DB-Name, Host, Port
|
||||||
|
connStr := "user=devuser password=devpass dbname=devdb host=localhost port=5432 sslmode=disable"
|
||||||
|
// Verbindung zur Datenbank öffnen
|
||||||
|
var err error
|
||||||
|
db, err = sql.Open("postgres", connStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Fehler beim Öffnen der DB-Verbindung:", err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// Verbindung testen
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Datenbank nicht erreichbar:", err)
|
||||||
|
}
|
||||||
|
log.Println("Verbindung zur Datenbank erfolgreich hergestellt.")
|
||||||
|
|
||||||
|
http.HandleFunc("/insert", handleFormRequestWithDB(insertToDB))
|
||||||
|
http.HandleFunc("/update", handleFormRequestWithDB(updateInDB))
|
||||||
|
fmt.Println("Server läuft auf localhost:8080...")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
const zahlen = [38, 0, 226, 384, 111, 500383];
|
||||||
|
|
||||||
|
for (let i = 0; i < zahlen.length; i++) {
|
||||||
|
const z = zahlen[i];
|
||||||
|
const ergebnis = (z === 0)
|
||||||
|
? "Null"
|
||||||
|
: (z % 2 === 0 ? "Gerade Zahl" : "Ungerade Zahl");
|
||||||
|
|
||||||
|
console.log(z, ": ", ergebnis);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
const sortiment = JSON.parse(
|
||||||
|
`[{ "produkt": "Joghurt", "preis": 2.49 },
|
||||||
|
{ "produkt": "Brot", "preis": 3.29 },
|
||||||
|
{ "produkt": "Käse", "preis": 8.99 },
|
||||||
|
{ "produkt": "Duschgel","preis": 2.79 }
|
||||||
|
]`);
|
||||||
|
|
||||||
|
const rabattiert = sortiment.map(
|
||||||
|
x => (
|
||||||
|
{
|
||||||
|
produkt: x.produkt,
|
||||||
|
preis: parseFloat((x.preis * 0.9).toFixed(2))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(rabattiert);
|
||||||
|
|
@ -0,0 +1,158 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Registrierung struct {
|
||||||
|
Vorname string `json:"vorname"`
|
||||||
|
Nachname string `json:"nachname"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Telefon string `json:"telefon"`
|
||||||
|
Sessions []string `json:"sessions"`
|
||||||
|
AGBAkzeptiert string `json:"agb"`
|
||||||
|
Newsletter string `json:"newsletter"`
|
||||||
|
Equipment string `json:"equipment"`
|
||||||
|
Format string `json:"format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseCheckboxValue(value string) string {
|
||||||
|
if value == "" || (value != "ja" && value != "on") {
|
||||||
|
return "nein"
|
||||||
|
}
|
||||||
|
return "ja"
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseRadiobuttonValue(value string) (string, error) {
|
||||||
|
if value == "" || (value != "praesenz" && value != "online") {
|
||||||
|
return "", errors.New("Auswahl nicht erlaubt.")
|
||||||
|
}
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func registrierungHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Nur POST-Anfragen erlaubt", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data Registrierung
|
||||||
|
|
||||||
|
contentType := r.Header.Get("Content-Type")
|
||||||
|
|
||||||
|
if contentType == "application/json" {
|
||||||
|
// JSON-Daten verarbeiten
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
if err := decoder.Decode(&data); err != nil {
|
||||||
|
http.Error(w, "Ungültiges JSON", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Vorname == "" {
|
||||||
|
http.Error(w, "Pflichtfeld fehlt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Nachname == "" {
|
||||||
|
http.Error(w, "Pflichtfeld fehlt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data.AGBAkzeptiert = parseCheckboxValue(data.AGBAkzeptiert)
|
||||||
|
if data.AGBAkzeptiert == "nein" {
|
||||||
|
http.Error(w, "AGB wurde nicht akzeptiert.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data.Newsletter = parseCheckboxValue(data.Newsletter)
|
||||||
|
data.Equipment = parseCheckboxValue(data.Equipment)
|
||||||
|
format, err := parseRadiobuttonValue(data.Format)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Ungültige Auswahl des Formats.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data.Format = format
|
||||||
|
} else {
|
||||||
|
// Formulardaten parsen und Überprüfen, ob ungültige Formulardaten gesendet wurde
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
http.Error(w, "Fehler beim Parsen des Formulars", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Überprüfen, ob leeres Formular gesendet wurde
|
||||||
|
if len(r.PostForm) == 0 {
|
||||||
|
http.Error(w, "Kein Formular gesendet", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Formulardaten auslesen und ggf. überprüfen
|
||||||
|
vorname := r.PostForm.Get("vorname")
|
||||||
|
if vorname == "" {
|
||||||
|
http.Error(w, "Pflichtfeld fehlt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nachname := r.PostForm.Get("nachname")
|
||||||
|
if nachname == "" {
|
||||||
|
http.Error(w, "Pflichtfeld fehlt.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
email := r.PostForm.Get("email")
|
||||||
|
telefon := r.PostForm.Get("telefon")
|
||||||
|
sessions := r.PostForm["sessions"]
|
||||||
|
agb := parseCheckboxValue(r.PostForm.Get("agb"))
|
||||||
|
if agb == "" {
|
||||||
|
http.Error(w, "AGB wurde nicht akzeptiert.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newsletter := parseCheckboxValue(r.PostForm.Get("newsletter"))
|
||||||
|
equipment := parseCheckboxValue(r.PostForm.Get("equipment"))
|
||||||
|
format, err := parseRadiobuttonValue(r.PostForm.Get("format"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Ungültige Auswahl des Formats.", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data = Registrierung{
|
||||||
|
Vorname: vorname,
|
||||||
|
Nachname: nachname,
|
||||||
|
Email: email,
|
||||||
|
Telefon: telefon,
|
||||||
|
Sessions: sessions,
|
||||||
|
AGBAkzeptiert: agb,
|
||||||
|
Newsletter: newsletter,
|
||||||
|
Equipment: equipment,
|
||||||
|
Format: format,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ausgabe im Terminal
|
||||||
|
fmt.Fprintf(w, "Neue Registrierung erhalten:\n")
|
||||||
|
fmt.Fprintf(w, "Vorname: %s\n", data.Vorname)
|
||||||
|
fmt.Fprintf(w, "Nachname: %s\n", data.Nachname)
|
||||||
|
fmt.Fprintf(w, "E-Mail: %s\n", data.Email)
|
||||||
|
fmt.Fprintf(w, "Telefon: %s\n", data.Telefon)
|
||||||
|
fmt.Fprintf(w, "Bevorzugte Sessions: \n")
|
||||||
|
for _, session := range data.Sessions {
|
||||||
|
fmt.Fprintf(w, " - %s\n", session)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "AGB akzeptiert: %s\n", data.AGBAkzeptiert)
|
||||||
|
fmt.Fprintf(w, "Newsletter: %s\n", data.Newsletter)
|
||||||
|
fmt.Fprintf(w, "Equipment benötigt: %s\n", data.Equipment)
|
||||||
|
fmt.Fprintf(w, "Teilnahmeformat: %s", data.Format)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/registrierung", registrierungHandler)
|
||||||
|
fmt.Println("Server läuft auf localhost:8080...")
|
||||||
|
http.ListenAndServe(":8080", nil)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue