mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-19 16:50:56 +00:00
feat: Add /quit API
This commit is contained in:
parent
6d1c62bbf0
commit
81dcfe0da7
3 changed files with 27 additions and 1 deletions
25
hub/route/quit.go
Normal file
25
hub/route/quit.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"os"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/metacubex/mihomo/hub/executor"
|
||||
)
|
||||
|
||||
func quitRouter() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Get("/", quitCore)
|
||||
return r
|
||||
}
|
||||
|
||||
func quitCore(w http.ResponseWriter, r *http.Request) {
|
||||
render.JSON(w, r, render.M{"status": "ok"})
|
||||
executor.Shutdown()
|
||||
if runtime.GOOS == "windows" {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
|
@ -91,6 +91,7 @@ func router(isDebug bool, withAuth bool) *chi.Mux {
|
|||
r.Mount("/dns", dnsRouter())
|
||||
r.Mount("/restart", restartRouter())
|
||||
r.Mount("/upgrade", upgradeRouter())
|
||||
r.Mount("/quit", quitRouter())
|
||||
addExternalRouters(r)
|
||||
|
||||
})
|
||||
|
|
2
main.go
2
main.go
|
@ -130,7 +130,7 @@ func main() {
|
|||
|
||||
termSign := make(chan os.Signal, 1)
|
||||
hupSign := make(chan os.Signal, 1)
|
||||
signal.Notify(termSign, syscall.SIGINT, syscall.SIGTERM)
|
||||
signal.Notify(termSign, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
|
||||
signal.Notify(hupSign, syscall.SIGHUP)
|
||||
for {
|
||||
select {
|
||||
|
|
Loading…
Add table
Reference in a new issue