-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (41 loc) · 1.22 KB
/
main.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
53
54
55
package main
import (
"fmt"
"log"
"net/http"
"strconv"
)
func main() {
configuration := Configuration{}
configuration.DefaultPath()
configuration.Open("")
if configuration.StartServices {
start_services()
}
//var day [24]Temperature
t := make(chan Temperature, 1)
towm := make(chan Temperature, 1)
dayc := make(chan []Temperature, 1)
go readData(&configuration, t, dayc)
go readDataOWM(&configuration, towm)
/*http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handler(w, r, t)
})*/
fs := http.FileServer(http.Dir(configuration.ConfPath+"."))
http.Handle("/", http.StripPrefix("/", fs))
http.HandleFunc("/api/v1/temp", func(w http.ResponseWriter, r *http.Request) {
handlerREST(w, r, t)
})
http.HandleFunc("/api/v1/tempowm", func(w http.ResponseWriter, r *http.Request) {
handlerRESTOWM(w, r, towm)
})
http.HandleFunc("/api/v1/tempday", func(w http.ResponseWriter, r *http.Request) {
handlerRESTDAY(w, r, dayc)
})
http.HandleFunc("/api/v1/os", func(w http.ResponseWriter, r *http.Request) {
handlerRESTOS(w, r, &configuration)
})
port := strconv.Itoa(configuration.ServerPort)
fmt.Println("web server on localhost:" + port)
log.Fatal(http.ListenAndServe(":" + port, nil))
}