-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
81 lines (65 loc) · 1.84 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/urfave/negroni"
)
var (
mainRouter *mux.Router
csvFile string
jsonFile string
wildNodesFile string
pluginFile string
sensorHardwareFile string
)
func init() {
csvFile = "init_data/manifest.csv"
jsonFile = "init_data/dataDict.json"
wildNodesFile = "init_data/wild_nodes.json"
pluginFile = "init_data/pluginData.json"
sensorHardwareFile = "init_data/sensor_hardware.json"
}
func createRouter() {
mainRouter = mux.NewRouter()
r := mainRouter
log.Println("Sage Data API")
api := r.PathPrefix("/api/v1").Subrouter()
api.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome to SAGE Data API")
})
// GET
// /nodes blades
api.Handle("/nodes-data", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getSageNodes)),
)).Methods(http.MethodGet)
api.Handle("/nodes-metadata", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getSageNodesMetadata)),
)).Methods(http.MethodGet)
api.Handle("/nodes-all", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getSageNodesAndDataDict)),
)).Methods(http.MethodGet)
// /nodes-wild
api.Handle("/nodes-wild-data", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getWildNodeData)),
)).Methods(http.MethodGet)
// /plugin
api.Handle("/plugin-data", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getSagePluginData)),
)).Methods(http.MethodGet)
// /sensor-hardware
api.Handle("/sensor-hardware-data", negroni.New(
negroni.HandlerFunc(authMW),
negroni.Wrap(http.HandlerFunc(getSensorHardwareData)),
)).Methods(http.MethodGet)
log.Fatalln(http.ListenAndServe(":8080", api))
}
func main() {
createRouter()
}