added some mini exercises

main
Oliver Stolle 2026-04-28 16:03:25 +02:00
parent f29b17d3c0
commit 0ee9b3151c
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package main
import "net/http"
type respExampleHandler int //typ ist egal => interface wichtig!!
func (hello respExampleHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { //Bedienung
w.Header().Set("custom_header", "Beleibiger Text")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusFound)
w.Write([]byte("<h1> Dies ist eine HTML-Ueberschrift</h1>"))
}
func main() {
var r respExampleHandler
http.ListenAndServe("localhost:8080", r) //Türsteher
}

View File

@ -0,0 +1,18 @@
package main
import (
"fmt"
"net/http"
)
type helloHandler int
func (hello helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World %d", hello)
}
func _main() {
var world helloHandler
world = 42
http.ListenAndServe("localhost:8080", world)
}