|
|
|
@ -12,8 +12,14 @@ import (
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
|
|
|
"github.com/go-chi/cors"
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
|
|
|
EnableCompression: true,
|
|
|
|
|
HandshakeTimeout: time.Second * 2,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type adminHandler struct {
|
|
|
|
|
Cache
|
|
|
|
|
Storage
|
|
|
|
@ -50,9 +56,11 @@ func NewAdminHandler(c Cache, s Storage, re *RuleEngine) http.Handler {
|
|
|
|
|
handler.Route("/api/v1", func(r chi.Router) {
|
|
|
|
|
r.Get("/metrics/log", RestHandler(a.getLog).ToHF())
|
|
|
|
|
r.Get("/metrics/stats", RestHandler(a.getStats).ToHF())
|
|
|
|
|
|
|
|
|
|
r.Get("/rules", RestHandler(a.getRules).ToHF())
|
|
|
|
|
r.Put("/rules", RestHandler(a.createRule).ToHF())
|
|
|
|
|
r.Delete("/rules/{id:[0-9]+}", RestHandler(a.deleteRule).ToHF())
|
|
|
|
|
|
|
|
|
|
r.Get("/recursors", RestHandler(a.getRecursors).ToHF())
|
|
|
|
|
r.Put("/recursors", RestHandler(a.addRecursor).ToHF())
|
|
|
|
|
// r.Put("/rules/lists", a.addRulelist)
|
|
|
|
@ -63,6 +71,7 @@ func NewAdminHandler(c Cache, s Storage, re *RuleEngine) http.Handler {
|
|
|
|
|
// r.Delete("/cache/purgeall", RestHandler(a.purgeAll).ToHF())
|
|
|
|
|
// r.Delete("/cache/purge", a.purgeKey)
|
|
|
|
|
// r.Get("/cache", a.getCacheContents)
|
|
|
|
|
r.HandleFunc("/signal", a.signal)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return a
|
|
|
|
@ -73,6 +82,18 @@ func (a *adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
a.h.ServeHTTP(w, r)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *adminHandler) signal(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
c, err := upgrader.Upgrade(w, r, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Print("could not upgrade to a websocket:", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer c.Close()
|
|
|
|
|
for {
|
|
|
|
|
// send any updates that come through to the client
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (a *adminHandler) addRecursor(r *http.Request) (*RestResponse, error) {
|
|
|
|
|
var recursorHttpInput RecursorRow
|
|
|
|
|
|
|
|
|
|