forked from WEB-IMB-WS2526/lab-development-imb
37 lines
764 B
Go
37 lines
764 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type reqExampleHandler int
|
|
|
|
func (hello reqExampleHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "Only GET requests are allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Method:", r.Method)
|
|
fmt.Println("URL:", r.URL.String())
|
|
fmt.Println("Host:", r.Host)
|
|
fmt.Println("Accept-Header", r.Header.Get("Accept"))
|
|
|
|
queryParams := r.URL.Query()
|
|
fmt.Println("Query Parameters:")
|
|
for key, values := range queryParams {
|
|
for _, value := range values {
|
|
fmt.Printf(" %s = %s\n", key, value)
|
|
}
|
|
}
|
|
|
|
w.Write([]byte("<h1>GET: http.Request-Beispiel<h1>"))
|
|
}
|
|
|
|
func main() {
|
|
var r reqExampleHandler
|
|
http.ListenAndServe("localhost:8080", r)
|
|
}
|