This commit is contained in:
YouROK
2020-11-06 16:49:18 +03:00
parent a1e17b1cf3
commit f92b9eebf3
11 changed files with 83 additions and 60 deletions

36
src/server/web/server.go Normal file
View File

@@ -0,0 +1,36 @@
package web
import (
"github.com/gin-gonic/gin"
"server/torr"
)
var (
BTS = torr.NewBTS()
waitChan = make(chan error)
)
func Start(port string) {
BTS.Connect()
route := gin.New()
route.Use(gin.Logger(), gin.Recovery())
route.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
waitChan <- route.Run(":" + port)
}
func Wait() error {
return <-waitChan
}
func Stop() {
BTS.Disconnect()
waitChan <- nil
}