Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (31 sloc) 945 Bytes
// Seriál "Programovací jazyk Go"
//
// Dvanáctá část
//
// Demonstrační příklad číslo 3:
// HTTP server se specifikací MIME typu odpovědí
package main
import (
"net/http"
)
func endpointHtml(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/html")
response := "<body><h1>Hello world!</h1></body>\n"
writer.Write([]byte(response))
}
func endpointText(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/plain")
response := "Hello world!\n"
writer.Write([]byte(response))
}
func endpointAsm(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/x-asm")
response := "START: brk\n"
writer.Write([]byte(response))
}
func main() {
http.HandleFunc("/html", endpointHtml)
http.HandleFunc("/text", endpointText)
http.HandleFunc("/asm", endpointAsm)
http.ListenAndServe(":8000", nil)
}
You can’t perform that action at this time.