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.
64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"git.sp4ke.com/sp4ke/bit4sat/storage"
|
|
"git.sp4ke.com/sp4ke/bit4sat/ws"
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-contrib/sessions"
|
|
"github.com/gin-contrib/sessions/redis"
|
|
"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())
|
|
|
|
// Setup Session
|
|
sessionStore, err := redis.NewStore(10, "tcp", "redis:6379",
|
|
"", []byte(SessionSecret))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
router.Use(sessions.Sessions("websocket-session", sessionStore))
|
|
|
|
//
|
|
//
|
|
//router.Use(secure.New(secure.Config{
|
|
//ContentSecurityPolicy: "default-src 'self'; script-src *; worker-src *",
|
|
////IsDevelopment: true,
|
|
//}))
|
|
|
|
return &API{
|
|
router: router,
|
|
}
|
|
}
|