You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
843 B
Go
51 lines
843 B
Go
package main
|
|
|
|
import (
|
|
"git.sp4ke.com/sp4ke/bit4sat/storage"
|
|
"git.sp4ke.com/sp4ke/bit4sat/ws"
|
|
"github.com/gin-contrib/cors"
|
|
"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")
|
|
{
|
|
|
|
uploadRoute.POST("", UploadCtrl.New)
|
|
uploadRoute.PUT(":id", UploadCtrl.Upload)
|
|
|
|
}
|
|
|
|
wsRoute := api.router.Group("/ws")
|
|
{
|
|
wsRoute.GET("/", ws.Serve)
|
|
wsRoute.GET("/WS", ws.Serve)
|
|
wsRoute.GET("/WSS", ws.Serve)
|
|
}
|
|
|
|
api.router.Run("0.0.0.0: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,
|
|
//}))
|
|
|
|
return &API{
|
|
router: router,
|
|
}
|
|
}
|