This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
/
gopherwink.go
61 lines (52 loc) · 1.94 KB
/
gopherwink.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
56
57
58
59
60
61
package main
import (
"fmt"
"github.com/icecreammatt/gopherwink/scheduler"
"github.com/rs/cors"
"github.com/sasbury/mini"
"net/http"
)
func main() {
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "OPTIONS", "PUT", "DELETE"},
AllowedHeaders: []string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "Authorization", "X-CSRF-Token"},
OptionsPassthrough: false,
})
router := NewRouter()
var latitude float64
var longitude float64
var connectionString string
var authkey string
var autoNightLights []int64
config, err := mini.LoadConfiguration("settings.ini")
if err != nil {
latitude = 0
longitude = 0
fmt.Println("Configuration Missing")
} else {
latitude = config.FloatFromSection("geo-location", "latitude", 0)
longitude = config.FloatFromSection("geo-location", "longitude", 0)
fmt.Println(latitude)
fmt.Println(longitude)
autoNightLights = config.IntegersFromSection("auto-night-lights", "deviceId")
fmt.Println(autoNightLights)
connectionString = config.StringFromSection("remote-client", "connectionString", "")
fmt.Println(connectionString)
authkey = config.StringFromSection("remote-client", "authkey", "")
fmt.Println(authkey)
}
scheduler.Start(60*1000, latitude, longitude, autoNightLights)
// TODO: Check for config to see if service is provided
// else ignore this part and do not enable the remote client
// if authkey != "" && connectionString != "" {
// fmt.Println("Starting remote socket connection")
// startSocketClient(connectionString, authkey)
// }
appPort := config.StringFromSection("port", "app", "5000")
fmt.Println("App Listening on port", appPort)
go http.ListenAndServe(":"+appPort, c.Handler(router))
staticPort := config.StringFromSection("port", "static", "80")
fmt.Println("Static Listening on port", staticPort)
panic(http.ListenAndServe(":"+staticPort, http.FileServer(http.Dir("/var/www/"))))
}