forked from WEB-IB-SS26/development-ib
added some mini exercises
parent
f29b17d3c0
commit
0ee9b3151c
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
Loading…
Reference in New Issue