You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
6 years ago
|
/*
|
||
|
Landesamt für Geoinformation und Landentwicklung, Referat 35
|
||
|
Einführung in die Sprache Go, 25.7.2017
|
||
6 years ago
|
Lektion 11: Ganz einfacher Webserver
|
||
6 years ago
|
*/
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
6 years ago
|
"net/http"
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
func handler00(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, "Guckuck %s!", r.URL.Path[1:])
|
||
|
fmt.Println(r.URL)
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
func handler01(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, `<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta charset="UTF-8"/>
|
||
|
<title>Testseite 01</title>
|
||
|
</head>
|
||
|
<body>Du befindest Dich auf Seite `+"%s!"+`</body>
|
||
|
</html>`, r.URL.Path[1:])
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
func handler02(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, `<?xml version='1.0' encoding='iso-8859-1'?>
|
||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
|
||
|
<head>
|
||
|
<meta charset="UTF-8"/>
|
||
|
<title>Testseite 01</title>
|
||
|
</head>
|
||
|
<body><b>Du</b> befindest Dich jetzt auf <i>Seite `+"%s!"+`</i></body>
|
||
|
</html>`, r.URL.Path[1:])
|
||
6 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
|
|
||
6 years ago
|
http.HandleFunc("/", handler00)
|
||
|
http.HandleFunc("/aa", handler01)
|
||
|
http.HandleFunc("/bb", handler02)
|
||
|
http.ListenAndServe(":8080", nil)
|
||
6 years ago
|
}
|