-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.go
54 lines (42 loc) · 2.23 KB
/
api.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
package main
import (
"github.com/geekgonecrazy/prismplus/controllers"
"github.com/geekgonecrazy/prismplus/sessions"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func apiServer() {
sessions.InitializeSessionStore()
router := echo.New()
router.Use(middleware.Logger())
router.Use(middleware.Recover())
router.Use(middleware.CORS())
router.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "web/public",
Index: "index.html",
HTML5: true,
}))
keyAuthConfig := middleware.KeyAuthConfig{KeyLookup: "header:Authorization", Validator: validateAdminKey}
router.GET("/api/v1/streamers", controllers.GetStreamersHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.POST("/api/v1/streamers", controllers.CreateStreamerHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.GET("/api/v1/streamers/:streamer", controllers.GetStreamerHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.DELETE("/api/v1/streamers/:streamer", controllers.DeleteStreamerHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.GET("/api/v1/streamer", controllers.GetMyStreamerHandler)
router.GET("/api/v1/streamer/destinations", controllers.GetMyStreamerDestinationsHandler)
router.POST("/api/v1/streamer/destinations", controllers.CreateMyStreamerDestinationHandler)
router.DELETE("/api/v1/streamer/destinations/:destination", controllers.RemoveMyStreamerDestinationHandler)
router.GET("/api/v1/sessions", controllers.GetSessionsHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.POST("/api/v1/sessions", controllers.CreateSessionHandler, middleware.KeyAuthWithConfig(keyAuthConfig))
router.GET("/api/v1/sessions/:session", controllers.GetSessionHandler)
router.POST("/api/v1/sessions/:session/destinations", controllers.AddDestinationHandler)
router.GET("/api/v1/sessions/:session/destinations", controllers.GetDestinationsHandler)
router.DELETE("/api/v1/sessions/:session/destinations/:destination", controllers.RemoveDestinationHandler)
router.DELETE("/api/v1/sessions/:session", controllers.DeleteSessionHandler)
router.Logger.Fatal(router.Start(":5383"))
}
func validateAdminKey(key string, c echo.Context) (bool, error) {
if key == *adminKey {
return true, nil
}
return false, nil
}