-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
51 lines (36 loc) · 956 Bytes
/
server.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
package main
import (
"fmt"
"time"
"github.com/ismar/dsa/distrybuted_systems_api/controllers"
middleware "github.com/ismar/dsa/distrybuted_systems_api/middleware"
"github.com/ismar/dsa/distrybuted_systems_api/utils"
"github.com/julienschmidt/httprouter"
"github.com/tylerb/graceful"
"github.com/urfave/negroni"
)
var (
val controllers.MeasuredValues
mdlw middleware.Middleware
)
var err error
func main() {
//Making initial DB Access
utils.GetSQLDB()
n := negroni.Classic()
n.Use(negroni.HandlerFunc(mdlw.CORS))
n.Use(negroni.HandlerFunc(mdlw.Preflight))
port := "8010"
serverIP := "192.168.0.19"
recovery := negroni.NewRecovery()
recovery.PrintStack = false
n.Use(recovery)
//Router
mux := httprouter.New()
mux.POST("/measured-distance", val.Save)
mux.GET("/data", val.GetData)
n.UseHandler(mux)
fmt.Println("Server started...")
n.Run(serverIP + ":" + port)
graceful.Run(serverIP+":"+port, 10*time.Second, n)
}