-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11_https_server.go
More file actions
39 lines (35 loc) · 1.06 KB
/
11_https_server.go
File metadata and controls
39 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Dvanáctá část
// Vývoj síťových aplikací v programovacím jazyku Go (pokračování)
// https://www.root.cz/clanky/vyvoj-sitovych-aplikaci-v-programovacim-jazyku-go-pokracovani/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z dvanácté části:
// https://github.com/tisnik/go-root/blob/master/article_12/README.md
//
// Demonstrační příklad číslo 11:
// Jednoduchý HTTPS server
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_12/11_https_server.html
package main
import (
"io"
"log"
"net/http"
)
func mainEndpoint(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/plain")
io.WriteString(writer, "Hello world!\n")
}
func main() {
http.HandleFunc("/", mainEndpoint)
err := http.ListenAndServeTLS(":4443", "server.crt", "server.key", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}