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"
|
2019-03-20 18:39:38 +00:00
|
|
|
"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() {
|
|
|
|
|
2019-03-29 12:10:06 +00:00
|
|
|
uploadRoute := api.router.Group("/api/upload")
|
2019-03-15 18:00:35 +00:00
|
|
|
{
|
|
|
|
|
2019-03-29 12:10:06 +00:00
|
|
|
uploadRoute.POST("", UploadCtrl.New)
|
|
|
|
uploadRoute.PUT(":id", UploadCtrl.Upload)
|
2019-03-15 18:00:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-29 12:10:06 +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 {
|
2019-03-20 18:39:38 +00:00
|
|
|
router := gin.Default()
|
|
|
|
router.Use(cors.Default())
|
2019-03-29 12:10:06 +00:00
|
|
|
//
|
|
|
|
//router.Use(secure.New(secure.Config{
|
|
|
|
//ContentSecurityPolicy: "default-src 'self'; script-src *; worker-src *",
|
|
|
|
////IsDevelopment: true,
|
|
|
|
//}))
|
2019-03-20 18:39:38 +00:00
|
|
|
|
2019-03-15 18:00:35 +00:00
|
|
|
return &API{
|
2019-03-20 18:39:38 +00:00
|
|
|
router: router,
|
2019-03-15 18:00:35 +00:00
|
|
|
}
|
|
|
|
}
|