forked from xcodersun/eywa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
120 lines (94 loc) · 4.09 KB
/
routes.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"github.com/rs/cors"
. "github.com/eywa/configs"
"github.com/eywa/handlers"
"github.com/eywa/middlewares"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
"net/http"
)
func DeviceRouter() http.Handler {
DeviceRouter := web.New()
DeviceRouter.Use(middleware.RealIP)
DeviceRouter.Use(middleware.RequestID)
DeviceRouter.Use(middlewares.AccessLogging)
DeviceRouter.Use(middleware.Recoverer)
DeviceRouter.Use(middleware.AutomaticOptions)
DeviceRouter.Get("/heartbeat", handlers.HeartBeatWs)
DeviceRouter.Get("/channels/:channel_id/devices/:device_id/ws", handlers.WsHandler)
DeviceRouter.Post("/channels/:channel_id/devices/:device_id/upload", handlers.HttpPushHandler)
DeviceRouter.Post("/channels/:channel_id/devices/:device_id/push", handlers.HttpPushHandler)
DeviceRouter.Get("/channels/:channel_id/devices/:device_id/poll", handlers.HttpLongPollingHandler)
DeviceRouter.Compile()
return DeviceRouter
}
func HttpRouter() http.Handler {
httpRouter := web.New()
httpRouter.Use(middleware.RealIP)
httpRouter.Use(middleware.RequestID)
httpRouter.Use(middlewares.AccessLogging)
httpRouter.Use(middleware.Recoverer)
httpRouter.Use(middleware.AutomaticOptions)
httpRouter.Get("/heartbeat", handlers.HeartBeatHttp)
httpRouter.Get("/greeting", handlers.Greeting)
httpRouter.Handle("/admin/*", AdminRouter())
httpRouter.Handle("/api/*", ApiRouter())
fs := http.FileServer(http.Dir(Config().Service.Assets))
httpRouter.Handle("/*", fs)
httpRouter.Compile()
return httpRouter
}
func AdminRouter() http.Handler {
admin := web.New()
admin.Use(middleware.SubRouter)
admin.Use(middlewares.AdminAuthenticator)
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
AllowedMethods: []string{"GET", "POST", "DELETE", "PUT"},
AllowCredentials: true,
})
admin.Use(c.Handler)
admin.Get("/login", handlers.Login)
admin.Get("/configs", handlers.GetConfig)
admin.Put("/configs", handlers.UpdateConfig)
admin.Get("/summary", handlers.GetSummary)
admin.Get("/tail", handlers.TailLog)
admin.Get("/channels", handlers.ListChannels)
admin.Post("/channels", handlers.CreateChannel)
admin.Get("/channels/:id", handlers.GetChannel)
admin.Delete("/channels/:id", handlers.DeleteChannel)
admin.Put("/channels/:id", handlers.UpdateChannel)
admin.Get("/dashboards", handlers.ListDashboards)
admin.Post("/dashboards", handlers.CreateDashboard)
admin.Get("/dashboards/:id", handlers.GetDashboard)
admin.Delete("/dashboards/:id", handlers.DeleteDashboard)
admin.Put("/dashboards/:id", handlers.UpdateDashboard)
admin.Get("/channels/:id/value", handlers.QueryValue)
admin.Get("/channels/:id/series", handlers.QuerySeries)
admin.Get("/channels/:id/raw", handlers.QueryRaw)
admin.Get("/channels/:id/tag_stats", handlers.GetChannelTagStats)
admin.Get("/channels/:id/index_stats", handlers.GetChannelIndexStats)
admin.Get("/channels/:id/request_template", handlers.GetChannelRequestTemplate)
admin.Get("/channels/:id/devices/:device_id/series", handlers.QuerySeries)
admin.Get("/connections/counts", handlers.ConnectionCounts)
admin.Get("/channels/:channel_id/connections/count", handlers.ConnectionCount)
admin.Get("/channels/:channel_id/connections/scan", handlers.ScanConnections)
admin.Get("/channels/:channel_id/devices/:device_id/attach", handlers.AttachConnection)
admin.Get("/channels/:channel_id/devices/:device_id/status", handlers.ConnectionStatus)
admin.Post("/channels/:channel_id/devices/:device_id/send", handlers.SendToDevice)
admin.Post("/channels/:channel_id/devices/:device_id/request", handlers.RequestToDevice)
return admin
}
func ApiRouter() http.Handler {
api := web.New()
api.Use(middleware.SubRouter)
api.Use(middlewares.ApiAuthenticator)
api.Get("/channels/:id/value", handlers.QueryValue)
api.Get("/channels/:id/series", handlers.QuerySeries)
api.Get("/channels/:channel_id/devices/:device_id/status", handlers.ConnectionStatus)
api.Post("/channels/:channel_id/devices/:device_id/send", handlers.SendToDevice)
api.Post("/channels/:channel_id/devices/:device_id/request", handlers.RequestToDevice)
return api
}