bit4sat/api.go

50 lines
828 B
Go
Raw Normal View History

2019-03-15 18:00:35 +00:00
package main
import (
2019-03-23 18:29:48 +00:00
"git.sp4ke.com/sp4ke/bit4sat/storage"
"github.com/gin-contrib/cors"
2019-03-15 18:00:35 +00:00
"github.com/gin-gonic/gin"
)
var (
UploadCtrl = storage.UploadCtrl{}
)
type API struct {
router *gin.Engine
}
func (api *API) Run() {
uploadRoute := api.router.Group("/api/upload")
2019-03-15 18:00:35 +00:00
{
uploadRoute.POST("", UploadCtrl.New)
uploadRoute.PUT(":id", UploadCtrl.Upload)
2019-03-15 18:00:35 +00:00
}
websocket := api.router.Group("/ws")
{
websocket.GET("/", serveWebsocket)
websocket.GET("/WS", serveWebsocket)
websocket.GET("/WSS", serveWebsocket)
}
2019-03-15 18:00:35 +00:00
api.router.Run(":8880")
}
func NewAPI() *API {
router := gin.Default()
router.Use(cors.Default())
//
//router.Use(secure.New(secure.Config{
//ContentSecurityPolicy: "default-src 'self'; script-src *; worker-src *",
////IsDevelopment: true,
//}))
2019-03-15 18:00:35 +00:00
return &API{
router: router,
2019-03-15 18:00:35 +00:00
}
}