06: Labor und Demos

main
Teena Steger 2025-11-05 09:52:37 +01:00
parent f86ffeea9f
commit b759c413c1
18 changed files with 974 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package main
import "fmt"
func main() {
//Strings
fmt.Println("go" + "lang")
//Integers
fmt.Println("1+1 =", 1+1)
//Floats
fmt.Println("7.0/3.0 =", 7.0/3.0)
//Boolean
fmt.Println(true && false)
fmt.Println(true || false)
fmt.Println(!true)
}

View File

@ -0,0 +1,23 @@
package main
import "fmt"
var z = "initial"
func main() {
var a = "initial"
fmt.Println(a)
var b, c int = 1, 2
fmt.Println(b, c)
var d = true
fmt.Println(d)
var e int
fmt.Println(e)
f := "apple"
fmt.Println(f)
}

View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"math"
)
const s string = "constant"
func main() {
fmt.Println(s)
const n = 500000000
const d = 3e20 / n
fmt.Println(d)
fmt.Println(int64(d))
fmt.Println(math.Sin(n))
}

View File

@ -0,0 +1,32 @@
package main
import "fmt"
func main() {
i := 1
for i <= 3 {
fmt.Println(i)
i = i + 1
}
for j := 0; j < 3; j++ {
fmt.Println(j)
}
for i := range 3 {
fmt.Println("range", i)
}
for {
fmt.Println("loop")
break
}
for n := range 6 {
if n%2 == 0 {
continue
}
fmt.Println(n)
}
}

View File

@ -0,0 +1,28 @@
package main
import "fmt"
func main() {
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}
if 8%4 == 0 {
fmt.Println("8 is divisible by 4")
}
if 8%2 == 0 || 7%2 == 0 {
fmt.Println("either 8 or 7 are even")
}
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}

View File

@ -0,0 +1,49 @@
package main
import (
"fmt"
"time"
)
func main() {
i := 2
fmt.Print("Write ", i, " as ")
switch i {
case 1:
fmt.Println("one")
case 2:
fmt.Println("two")
case 3:
fmt.Println("three")
}
switch time.Now().Weekday() {
case time.Saturday, time.Sunday:
fmt.Println("It's the weekend")
default:
fmt.Println("It's a weekday")
}
t := time.Now()
switch {
case t.Hour() < 12:
fmt.Println("It's before noon")
default:
fmt.Println("It's after noon")
}
whatAmI := func(i interface{}) {
switch t := i.(type) {
case bool:
fmt.Println("I'm a bool")
case int:
fmt.Println("I'm an int")
default:
fmt.Printf("Don't know type %T\n", t)
}
}
whatAmI(true)
whatAmI(1)
whatAmI("hey")
}

View File

@ -0,0 +1,38 @@
package main
import "fmt"
func main() {
var a [5]int
fmt.Println("emp:", a)
a[4] = 100
fmt.Println("set:", a)
fmt.Println("get:", a[4])
fmt.Println("len:", len(a))
b := [5]int{1, 2, 3, 4, 5}
fmt.Println("dcl:", b)
b = [...]int{1, 2, 3, 4, 5}
fmt.Println("dcl:", b)
b = [...]int{100, 3: 400, 500}
fmt.Println("idx:", b)
var twoD [2][3]int
for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ {
twoD[i][j] = i + j
}
}
fmt.Println("2d: ", twoD)
twoD = [2][3]int{
{1, 2, 3},
{1, 2, 3},
}
fmt.Println("2d: ", twoD)
}

View File

@ -0,0 +1,24 @@
package main
import "fmt"
func zeroval(ival int) {
ival = 0
}
func zeroptr(iptr *int) {
*iptr = 0
}
func main() {
i := 1
fmt.Println("initial:", i)
zeroval(i)
fmt.Println("zeroval:", i)
zeroptr(&i)
fmt.Println("zeroptr:", i)
fmt.Println("pointer:", &i)
}

View File

@ -0,0 +1,58 @@
package main
import (
"fmt"
"slices"
)
func main() {
var s []string
fmt.Println("uninit:", s, s == nil, len(s) == 0)
s = make([]string, 3)
fmt.Println("emp:", s, "len:", len(s), "cap:", cap(s))
s[0] = "a"
s[1] = "b"
s[2] = "c"
fmt.Println("set:", s)
fmt.Println("get:", s[2])
fmt.Println("len:", len(s))
s = append(s, "d")
s = append(s, "e", "f")
fmt.Println("apd:", s)
c := make([]string, len(s))
copy(c, s)
fmt.Println("cpy:", c)
l := s[2:5]
fmt.Println("sl1:", l)
l = s[:5]
fmt.Println("sl2:", l)
l = s[2:]
fmt.Println("sl3:", l)
t := []string{"g", "h", "i"}
fmt.Println("dcl:", t)
t2 := []string{"g", "h", "i"}
if slices.Equal(t, t2) {
fmt.Println("t == t2")
}
twoD := make([][]int, 3)
for i := 0; i < 3; i++ {
innerLen := i + 1
twoD[i] = make([]int, innerLen)
for j := 0; j < innerLen; j++ {
twoD[i][j] = i + j
}
}
fmt.Println("2d: ", twoD)
}

View File

@ -0,0 +1,42 @@
package main
import (
"fmt"
"maps"
)
func main() {
m := make(map[string]int)
m["k1"] = 7
m["k2"] = 13
fmt.Println("map:", m)
v1 := m["k1"]
fmt.Println("v1:", v1)
v3 := m["k3"]
fmt.Println("v3:", v3)
fmt.Println("len:", len(m))
// delete(m, "k2")
// fmt.Println("map:", m)
// clear(m)
// fmt.Println("map:", m)
wert, prs := m["k2"]
fmt.Println("prs:", prs)
fmt.Println("wert:", wert)
n := map[string]int{"foo": 1, "bar": 2}
fmt.Println("map:", n)
n2 := map[string]int{"foo": 1, "bar": 2}
if maps.Equal(n, n2) {
fmt.Println("n == n2")
}
}

View File

@ -0,0 +1,36 @@
package main
import "fmt"
func plus(a int, b int) int {
return a + b
}
func plusPlus(a, b, c int) int {
return a + b + c
}
func plusNamed(a, b int) (result int) {
result = a + b
return
}
func plusDescription(a int, b int) (int, string) {
result := a + b
return result, fmt.Sprintf("%d+%d = %d", a, b, result)
}
func main() {
res := plus(1, 2)
fmt.Println("1+2 =", res)
res = plusPlus(1, 2, 3)
fmt.Println("1+2+3 =", res)
res = plusNamed(1, 2)
fmt.Println("1+2 =", res)
_, desc := plusDescription(1, 2)
fmt.Println(desc)
}

View File

@ -0,0 +1,7 @@
package hello
import "fmt"
func main() {
fmt.Println("hello world")
}

View File

@ -0,0 +1,54 @@
# Übungsblatt 06
## Nginx-Übung: Eigene Website
_Keine Abgabe erforderlich_
**Aufgabenstellung**: Nginx installieren und testen:
- MacOS: [Installationsanweisungen MacOS](installation_macos.md)
- Windows: [Installationsanweisungen MacOS](installation_win.md)
- Linux: [Installationsanweisungen MacOS](installation_linux.md)
## Apache-Übung: Eigene Website
_Keine Abgabe erforderlich_
**Aufgabenstellung**: Apache installieren und testen:
- MacOS: [Installationsanweisungen MacOS](installation_macos.md)
- Windows: [Installationsanweisungen MacOS](installation_win.md)
- Linux: [Installationsanweisungen MacOS](installation_linux.md)
## SWAGGER-Übung
**Aufgabenstellung**: Erstellen Sie eine OpenAPI-Spezifikation für die Workshop-Anmeldung aus Übungsblatt 04.
#### Arbeitsschritte
1. Setzen die OpenAPI-Version auf `3.0.0`.
2. Setzen Sie Meta-Daten wie Titel und API-Version im Info-Objekt.
3. Setzen Sie `https://web2-637691723779.europe-west1.run.app` als URL im Servers-Objekt.
4. Setzen Sie einen **Pfad** `/registrierung` für die HTTP-Methode `POST`. Definieren Sie eine Beschreibung, den Request-Body sowie mögliche Antworten des Servers.
1. Request-Body für die Übergabe von **Formulardaten**
2. Request-Body für die Übergabe von **JSON-Daten**
_Tipp: Verwenden Sie das Components-Objekt._
5. Verwenden Sie Enums (https://swagger.io/docs/specification/v3_0/data-models/enums/) für die Spezifikation der Checkboxen und der Radiobuttons (s. Hinweis unten).
- Beispiel für `enum` in JSON-OpenAPI:
```json
"farbe": {
"type": "string",
"enum": ["rot","gruen","blau"],
"example": "gruen"
},
```
6. Testen Sie Ihre API-Spezifikation mit Swagger.
#### Hinweis
Der serverseitige API-Endpunkt hat sich geändert (neue URL: `https://web2-637691723779.europe-west1.run.app`) und wurde nun folgendermaßen implementiert:
1. Für **agb**, **newsletter** und **equipment** werden die Werte (`value`-Attribut) _ja_ und _on_ akzeptiert.
2. Für **format** werden die Werte (`value`-Attribut) _online_ und _praesenz_ akzeptiert.

View File

@ -0,0 +1,102 @@
## Ergänzung für macOS: Vollständige Deinstallation von Nginx und Apache
### Nginx vollständig entfernen
1. Dienst stoppen:
```bash
brew services stop nginx
```
2. Nginx deinstallieren:
```bash
brew uninstall nginx
```
3. Konfigurationsdateien und Logs löschen:
Je nach Mac-Chip:
- Intel-Mac:
```bash
sudo rm -rf /usr/local/etc/nginx /usr/local/var/log/nginx
```
- Apple Silicon:
```bash
sudo rm -rf /opt/homebrew/etc/nginx /opt/homebrew/var/log/nginx
```
4. Benutzerverzeichnis löschen (falls verwendet):
```bash
rm -rf ~/meine-website
```
---
### Apache vollständig entfernen
1. Dienst stoppen:
```bash
brew services stop httpd
```
2. Apache deinstallieren:
```bash
brew uninstall httpd
```
3. Konfigurationsdateien und Logs löschen:
- Intel-Mac:
```bash
sudo rm -rf /usr/local/etc/httpd /usr/local/var/log/httpd
```
- Apple Silicon:
```bash
sudo rm -rf /opt/homebrew/etc/httpd /opt/homebrew/var/log/httpd
```
4. Benutzerverzeichnis löschen:
```bash
rm -rf ~/meine-website
```
---
## Ergänzung für Windows: Vollständige Deinstallation von Nginx und Apache
### Nginx vollständig entfernen
1. Dienst stoppen (falls aktiv):
Öffnen Sie die Eingabeaufforderung als Administrator:
```cmd
nginx -s stop
```
2. Nginx-Verzeichnis löschen:
```cmd
rmdir /S /Q C:\nginx
```
3. Temporäre Dateien und Logs entfernen (falls vorhanden):
- Prüfen Sie z.B. `C:\nginx\logs` oder andere benutzerdefinierte Pfade.
---
### Apache vollständig entfernen
1. Dienst stoppen (falls aktiv):
```cmd
httpd -k stop
```
2. Apache-Verzeichnis löschen:
```cmd
rmdir /S /Q C:\Apache24
```
3. Benutzerverzeichnis löschen:
```cmd
rmdir /S /Q C:\Apache24\htdocs\meine-website
```

View File

@ -0,0 +1,34 @@
## Homebrew installieren (macOS)
1. **Terminal öffnen**
Öffnen Sie das Programm „Terminal“. Sie finden es über Spotlight (⌘ + Leertaste → „Terminal“ eingeben).
2. **Installationsbefehl ausführen**
Kopieren Sie den folgenden Befehl und fügen Sie ihn ins Terminal ein:
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
3. **Anweisungen im Terminal folgen**
Während der Installation werden Sie möglicherweise nach Ihrem macOS-Passwort gefragt. Geben Sie es ein und bestätigen Sie mit Enter. Die Installation kann einige Minuten dauern.
4. **Pfad konfigurieren (nur bei Apple Silicon Macs)**
Wenn Sie einen Mac mit M1/M2/M3-Chip verwenden, fügen Sie Homebrew zum Pfad hinzu:
```bash
echo >> /Users/{IhrUser}/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{IhrUser}/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```
Bei Intel-Macs ist dieser Schritt nicht erforderlich.
5. **Installation testen**
Prüfen Sie, ob Homebrew korrekt installiert wurde:
```bash
brew --version
```
Sie sollten eine Versionsnummer sehen, z.B. `Homebrew 4.x.x`.

View File

@ -0,0 +1,161 @@
# Anleitung: Eigene Website mit Nginx oder Apache
## Version für Linux
### Voraussetzungen
- Linux-Distribution mit `apt`-Paketverwaltung (z.B. Ubuntu, Debian)
- Terminalzugriff
- Dev-Container schließen (!)
---
### Eigene Website mit Nginx unter Linux
1. Installieren Sie Nginx:
```bash
sudo apt update
sudo apt install nginx
```
2. Erstellen Sie Ihren Projektordner:
```bash
mkdir -p /home/{IhrVerzeichnis}/meine-website
echo "<h1>Willkommen bei {IhrName}</h1>" > /home/{IhrVerzeichnis}/meine-website/index.html
```
3. Erstellen Sie eine neue Nginx-Konfiguration:
```bash
sudo nano /etc/nginx/sites-available/{IhrName}
```
Inhalt der Datei:
```nginx
server {
listen 80;
server_name localhost;
root /home/{IhrVerzeichnis}/meine-website;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
```
4. Aktivieren Sie die Konfiguration und deaktivieren Sie die Standardseite:
```bash
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/{IhrName} /etc/nginx/sites-enabled/
```
5. Zugriffsrechte prüfen:
```bash
sudo chmod o+x /home/{IhrVerzeichnis}
sudo chmod -R o+r /home/{IhrVerzeichnis}/meine-website
```
6. Nginx neu laden:
```bash
sudo nginx -t
sudo systemctl reload nginx
```
7. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost
```
8. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
9. Nginx stoppen:
```bash
sudo systemctl stop nginx
```
10. Nginx vollständig entfernen:
```bash
sudo apt remove nginx nginx-common
sudo apt purge nginx nginx-common
sudo apt autoremove
rm -r /home/{IhrVerzeichnis}/meine-website
sudo rm -r /etc/nginx /var/log/nginx
```
---
### Eigene Website mit Apache unter Linux
1. Installieren Sie Apache:
```bash
sudo apt update
sudo apt install apache2
```
2. Erstellen Sie Ihren Projektordner:
```bash
mkdir -p /home/{IhrVerzeichnis}/meine-website
echo "<h1>Willkommen bei {IhrName}</h1>" > /home/{IhrVerzeichnis}/meine-website/index.html
```
3. Erstellen Sie eine neue Apache-Konfiguration:
```bash
sudo nano /etc/apache2/sites-available/{IhrName}.conf
```
Inhalt der Datei:
```apache
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/{IhrVerzeichnis}/meine-website
<Directory /home/{IhrVerzeichnis}/meine-website">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
```
4. Aktivieren Sie die Konfiguration und deaktivieren Sie die Standardseite:
```bash
sudo a2dissite 000-default.conf
sudo a2ensite {IhrName}.conf
```
5. Zugriffsrechte prüfen:
```bash
sudo chmod o+x /home/{IhrVerzeichnis}
sudo chmod -R o+r /home/{IhrVerzeichnis}/meine-website
```
6. Apache neu laden:
```bash
sudo apache2ctl configtest
sudo systemctl reload apache2
```
7. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost
```
8. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
9. Apache stoppen:
```bash
sudo systemctl stop apache2
```
10. Apache vollständig entfernen:
```bash
sudo apt remove apache2 apache2-utils apache2-bin apache2-data
sudo apt purge apache2 apache2-utils apache2-bin apache2-data
sudo apt autoremove
rm -r /home/{IhrVerzeichnis}/meine-website
sudo rm -r /etc/apache2 /var/log/apache2
```

View File

@ -0,0 +1,135 @@
# Anleitung: Eigene Website mit Nginx oder Apache
## Version für macOS
### Voraussetzungen
- macOS mit installiertem Homebrew
- Terminalzugriff
- Dev-Container schließen (!)
---
### Eigene Website mit Nginx unter macOS
1. Installieren Sie Nginx:
```bash
brew install nginx
```
2. Erstellen Sie Ihren Projektordner:
```bash
mkdir -p ~/meine-website
echo "<h1>Willkommen bei {IhrName}</h1>" > ~/meine-website/index.html
```
3. Passen Sie die Nginx-Konfiguration an:
Der Pfad zur Konfigurationsdatei hängt vom verwendeten Mac-Chip ab:
- Intel-Mac:
```bash
nano /usr/local/etc/nginx/nginx.conf
```
- Apple Silicon (M1/M2/M3):
```bash
nano /opt/homebrew/etc/nginx/nginx.conf
```
Fügen Sie am Ende der Datei folgenden Server-Block hinzu oder passen Sie den bestehenden an:
```nginx
server {
listen 8080;
server_name localhost;
location / {
root /Users/{IhrUser}/meine-website;
index index.html index.htm;
try_files $uri $uri/ =404;
}
}
```
4. Starten Sie Nginx:
```bash
brew services start nginx
```
5. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost:8080
```
6. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
7. Nginx stoppen
```cmd
brew services stop nginx
````
8. Nginx vollständig entfernen:
Siehe [Deinstallations-Anweisungen](deinstallation.md).
---
### Eigene Website mit Apache unter macOS
1. Installieren Sie Apache:
```bash
brew install httpd
```
2. Erstellen Sie Ihren Projektordner:
```bash
mkdir -p ~/meine-website
echo "<h1>Willkommen bei {IhrUser}</h1>" > ~/meine-website/index.html
```
3. Passen Sie die Apache-Konfiguration an:
Der Pfad zur Konfigurationsdatei hängt ebenfalls vom Mac-Chip ab:
- Intel-Mac:
```bash
nano /usr/local/etc/httpd/httpd.conf
```
- Apple Silicon:
```bash
nano /opt/homebrew/etc/httpd/httpd.conf
```
Fügen Sie am Ende der Datei folgenden VirtualHost hinzu:
```apache
<VirtualHost *:8080>
DocumentRoot "/Users/{IhrUser}/meine-website"
ServerName localhost
<Directory "/Users/{IhrUser}/meine-website">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
```
4. Starten Sie Apache:
```bash
brew services start httpd
```
5. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost:8080
```
6. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
7. Apache stoppen:
```bash
brew services stop httpd
```
8. Apache vollständig entfernen
Siehe [Deinstallations-Anweisungen](deinstallation.md).

View File

@ -0,0 +1,111 @@
# Anleitung: Eigene Website mit Nginx oder Apache
## Version für Windows (ohne WSL)
### Voraussetzungen
- Windows 10 oder 11
- Administratorrechte
- Dev-Container schließen (!)
- Nginx oder Apache für Windows installiert
---
### Eigene Website mit Nginx unter Windows
1. Laden Sie Nginx für Windows herunter:
- Website: https://nginx.org/en/download.html
- Entpacken Sie die ZIP-Datei z.B. nach `C:\nginx`
2. Erstellen Sie Ihren Projektordner:
- Pfad: `C:\nginx\html\meine-website`
- Datei: `index.html` mit folgendem Inhalt:
```html
<h1>Willkommen bei {IhrName}</h1>
```
3. Passen Sie die Konfiguration an:
- Datei: `C:\nginx\conf\nginx.conf`
```nginx
server {
listen 8080;
server_name localhost;
location / {
root /Users/{IhrUser}/meine-website;
index index.html index.htm;
try_files $uri $uri/ =404;
}
}
```
4. Starten Sie Nginx:
Öffnen Sie die Eingabeaufforderung als Administrator:
```cmd
cd C:\nginx
start nginx
```
5. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost:8080
```
6. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
7. Nginx stoppen
```cmd
nginx -s stop
````
8. Nginx vollständig entfernen:
Siehe [Deinstallations-Anweisungen](deinstallation.md).
---
### Eigene Website mit Apache unter Windows
1. Laden Sie Apache für Windows herunter:
- Website: https://www.apachelounge.com/download/
- Installieren Sie Apache z.B. nach `C:\Apache24`
2. Erstellen Sie Ihren Projektordner:
- Pfad: `C:\Apache24\htdocs\meine-website`
- Datei: `index.html` mit folgendem Inhalt:
```html
<h1>Willkommen bei {IhrName}</h1>
```
3. Passen Sie die Konfiguration an:
- Datei: `C:\Apache24\conf\httpd.conf`
```apache
DocumentRoot "C:/Apache24/htdocs/meine-website"
<Directory "C:/Apache24/htdocs/meine-website">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
```
4. Starten Sie Apache:
Öffnen Sie die Eingabeaufforderung als Administrator:
```cmd
httpd
```
5. Testen Sie Ihre Website:
Öffnen Sie im Browser:
```
http://localhost
```
6. Kopieren Sie Ihre Rezepte-Sammlung aus Übungsblatt 02 in Ihren Projektordner (`meine-website`). Benennen Sie die Hauptseite mit der Tabelle um zu `index.html`. Aktualisieren Sie dann die Webseite im Browser.
7. Apache stoppen:
```bash
httpd -k stop
```
8. Apache vollständig entfernen
Siehe [Deinstallations-Anweisungen](deinstallation.md).