mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-30 12:31:31 +00:00
34 lines
742 B
Go
34 lines
742 B
Go
package clashapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
"github.com/sagernet/sing/service"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/render"
|
|
)
|
|
|
|
func cacheRouter(ctx context.Context) http.Handler {
|
|
r := chi.NewRouter()
|
|
r.Post("/fakeip/flush", flushFakeip(ctx))
|
|
return r
|
|
}
|
|
|
|
func flushFakeip(ctx context.Context) func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
cacheFile := service.FromContext[adapter.CacheFile](ctx)
|
|
if 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)
|
|
}
|
|
}
|