mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-20 01:00:56 +00:00
add shutdown core router
This commit is contained in:
parent
2e87c6f4da
commit
ec5d90a604
2 changed files with 32 additions and 0 deletions
|
@ -93,6 +93,7 @@ func Start(addr string, tlsAddr string, secret string,
|
|||
r.Mount("/cache", cacheRouter())
|
||||
r.Mount("/dns", dnsRouter())
|
||||
r.Mount("/restart", restartRouter())
|
||||
r.Mount("/shutdown", shutdownRouter())
|
||||
r.Mount("/upgrade", upgradeRouter())
|
||||
addExternalRouters(r)
|
||||
|
||||
|
|
31
hub/route/shutdown.go
Normal file
31
hub/route/shutdown.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/metacubex/mihomo/hub/executor"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
func shutdownRouter() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Post("/", shutdown)
|
||||
return r
|
||||
}
|
||||
|
||||
func shutdown(w http.ResponseWriter, r *http.Request) {
|
||||
render.JSON(w, r, render.M{"status": "ok"})
|
||||
if f, ok := w.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
|
||||
go shutdownExecutable()
|
||||
}
|
||||
|
||||
func shutdownExecutable() {
|
||||
executor.Shutdown()
|
||||
os.Exit(0)
|
||||
}
|
Loading…
Add table
Reference in a new issue