-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
52 lines (43 loc) · 1.35 KB
/
router.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"net/http"
"fmt"
"encoding/json"
)
func handlerREST(w http.ResponseWriter, r *http.Request, t <-chan Temperature) {
if len(t) > 0 {
temps.actual = <-t
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(temps.actual); err != nil {
fmt.Fprintf(w, "Error", err)
}
}
func handlerRESTOWM(w http.ResponseWriter, r *http.Request, t <-chan Temperature) {
if len(t) > 0 {
temps.owm = <-t
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(temps.owm); err != nil {
fmt.Fprintf(w, "Error", err)
}
}
func handlerRESTDAY(w http.ResponseWriter, r *http.Request, dayc <-chan []Temperature) {
if len(dayc) > 0 {
//day := <-dayc
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
/*if err := json.NewEncoder(w).Encode(temps.actual); err != nil {
fmt.Fprintf(w, "Error", err)
}*/
json := "[ [\"Hour\", \"ºC\"], [\"09h\", 24.56],[\"10h\", 26.34],[\"11h\", 27.12],[\"12h\", 27.32],[\"13h\", 27.52]]"
fmt.Fprintf(w, json)
}
func handlerRESTOS(w http.ResponseWriter, r *http.Request, conf *Configuration) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, conf.OS)
}