-
Notifications
You must be signed in to change notification settings - Fork 4
/
plotly10.go
38 lines (33 loc) · 1.03 KB
/
plotly10.go
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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Padesátá první část
// Tvorba grafů v jazyce Go: kreslení ve webovém klientu
// https://www.root.cz/clanky/tvorba-grafu-v-jazyce-go-kresleni-ve-webovem-klientu/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z padesáté první části:
// https://github.com/tisnik/go-root/blob/master/article_51/README.md
package main
import (
"encoding/json"
"log"
"net/http"
)
func valuesHandler(writer http.ResponseWriter, request *http.Request) {
values := []float64{20, 30, 40, 50}
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
json.NewEncoder(writer).Encode(values)
}
func startHttpServer(address string) {
log.Printf("Starting server on address %s", address)
http.Handle("/", http.FileServer(http.Dir("plotly10/")))
http.HandleFunc("/values", valuesHandler)
http.ListenAndServe(address, nil)
}
func main() {
startHttpServer(":8080")
}