add shutdown

This commit is contained in:
YouROK
2020-11-19 10:26:29 +03:00
parent 469c145938
commit c9b2e0938d
5 changed files with 73 additions and 41 deletions

View File

@@ -1,7 +1,12 @@
package api
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
sets "server/settings"
"server/torr"
"server/version"
)
@@ -11,6 +16,7 @@ type requestI struct {
func SetupRoute(route *gin.Engine) {
route.GET("/echo", echo)
route.GET("/shutdown", shutdown)
route.POST("/settings", settings)
@@ -29,3 +35,15 @@ func SetupRoute(route *gin.Engine) {
func echo(c *gin.Context) {
c.String(200, "%v", version.Version)
}
func shutdown(c *gin.Context) {
if sets.IsReadOnly() {
c.Status(http.StatusForbidden)
return
}
c.Status(200)
go func() {
time.Sleep(1000)
torr.Shutdown()
}()
}