sing-box/experimental/clashapi/cache.go

31 lines
690 B
Go
Raw Permalink Normal View History

2022-07-19 14:16:49 +00:00
package clashapi
import (
"net/http"
2023-03-25 04:03:23 +00:00
"github.com/sagernet/sing-box/adapter"
2022-07-19 14:16:49 +00:00
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
)
2023-03-25 04:03:23 +00:00
func cacheRouter(router adapter.Router) http.Handler {
2022-07-19 14:16:49 +00:00
r := chi.NewRouter()
2023-03-25 04:03:23 +00:00
r.Post("/fakeip/flush", flushFakeip(router))
2022-07-19 14:16:49 +00:00
return r
}
2023-03-25 04:03:23 +00:00
func flushFakeip(router adapter.Router) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if cacheFile := router.ClashServer().CacheFile(); cacheFile != nil {
err := cacheFile.FakeIPReset()
if err != nil {
render.Status(r, http.StatusInternalServerError)
render.JSON(w, r, newError(err.Error()))
return
}
}
render.NoContent(w, r)
}
2022-07-19 14:16:49 +00:00
}