github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/experimental/clashapi/cache.go (about) 1 package clashapi 2 3 import ( 4 "net/http" 5 6 "github.com/inazumav/sing-box/adapter" 7 8 "github.com/go-chi/chi/v5" 9 "github.com/go-chi/render" 10 ) 11 12 func cacheRouter(router adapter.Router) http.Handler { 13 r := chi.NewRouter() 14 r.Post("/fakeip/flush", flushFakeip(router)) 15 return r 16 } 17 18 func flushFakeip(router adapter.Router) func(w http.ResponseWriter, r *http.Request) { 19 return func(w http.ResponseWriter, r *http.Request) { 20 if cacheFile := router.ClashServer().CacheFile(); cacheFile != nil { 21 err := cacheFile.FakeIPReset() 22 if err != nil { 23 render.Status(r, http.StatusInternalServerError) 24 render.JSON(w, r, newError(err.Error())) 25 return 26 } 27 } 28 render.NoContent(w, r) 29 } 30 }