mirror of https://github.com/status-im/go-waku.git
chore: use go-chi for rest server instead of archived gorilla/rpc
- RPC server is not modified since it's going to be deprecated
This commit is contained in:
parent
f0eaa84aad
commit
9731810b8d
|
@ -3,13 +3,13 @@ package rest
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/waku-org/go-waku/waku/v2/node"
|
||||
)
|
||||
|
||||
type DebugService struct {
|
||||
node *node.WakuNode
|
||||
mux *mux.Router
|
||||
mux *chi.Mux
|
||||
}
|
||||
|
||||
type InfoArgs struct {
|
||||
|
@ -23,14 +23,14 @@ type InfoReply struct {
|
|||
const ROUTE_DEBUG_INFOV1 = "/debug/v1/info"
|
||||
const ROUTE_DEBUG_VERSIONV1 = "/debug/v1/info"
|
||||
|
||||
func NewDebugService(node *node.WakuNode, m *mux.Router) *DebugService {
|
||||
func NewDebugService(node *node.WakuNode, m *chi.Mux) *DebugService {
|
||||
d := &DebugService{
|
||||
node: node,
|
||||
mux: m,
|
||||
}
|
||||
|
||||
m.HandleFunc(ROUTE_DEBUG_INFOV1, d.getV1Info).Methods(http.MethodGet)
|
||||
m.HandleFunc(ROUTE_DEBUG_VERSIONV1, d.getV1Version).Methods(http.MethodGet)
|
||||
m.Get(ROUTE_DEBUG_INFOV1, d.getV1Info)
|
||||
m.Get(ROUTE_DEBUG_VERSIONV1, d.getV1Version)
|
||||
|
||||
return d
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/waku-org/go-waku/waku/v2/node"
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol"
|
||||
|
@ -20,7 +21,6 @@ const ROUTE_RELAY_MESSAGESV1 = "/relay/v1/messages/{topic}"
|
|||
|
||||
type RelayService struct {
|
||||
node *node.WakuNode
|
||||
mux *mux.Router
|
||||
cancel context.CancelFunc
|
||||
|
||||
log *zap.Logger
|
||||
|
@ -32,10 +32,9 @@ type RelayService struct {
|
|||
runner *runnerService
|
||||
}
|
||||
|
||||
func NewRelayService(node *node.WakuNode, m *mux.Router, cacheCapacity int, log *zap.Logger) *RelayService {
|
||||
func NewRelayService(node *node.WakuNode, m *chi.Mux, cacheCapacity int, log *zap.Logger) *RelayService {
|
||||
s := &RelayService{
|
||||
node: node,
|
||||
mux: m,
|
||||
log: log.Named("relay"),
|
||||
cacheCapacity: cacheCapacity,
|
||||
messages: make(map[string][]*pb.WakuMessage),
|
||||
|
@ -43,10 +42,10 @@ func NewRelayService(node *node.WakuNode, m *mux.Router, cacheCapacity int, log
|
|||
|
||||
s.runner = newRunnerService(node.Broadcaster(), s.addEnvelope)
|
||||
|
||||
m.HandleFunc(ROUTE_RELAY_SUBSCRIPTIONSV1, s.postV1Subscriptions).Methods(http.MethodPost)
|
||||
m.HandleFunc(ROUTE_RELAY_SUBSCRIPTIONSV1, s.deleteV1Subscriptions).Methods(http.MethodDelete)
|
||||
m.HandleFunc(ROUTE_RELAY_MESSAGESV1, s.getV1Messages).Methods(http.MethodGet)
|
||||
m.HandleFunc(ROUTE_RELAY_MESSAGESV1, s.postV1Message).Methods(http.MethodPost)
|
||||
m.Post(ROUTE_RELAY_SUBSCRIPTIONSV1, s.postV1Subscriptions)
|
||||
m.Delete(ROUTE_RELAY_SUBSCRIPTIONSV1, s.deleteV1Subscriptions)
|
||||
m.Get(ROUTE_RELAY_MESSAGESV1, s.getV1Messages)
|
||||
m.Post(ROUTE_RELAY_MESSAGESV1, s.postV1Message)
|
||||
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/waku-org/go-waku/waku/v2/node"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -25,11 +25,12 @@ func NewWakuRest(node *node.WakuNode, address string, port int, enableAdmin bool
|
|||
wrpc := new(WakuRest)
|
||||
wrpc.log = log.Named("rest")
|
||||
|
||||
mux := mux.NewRouter()
|
||||
mux := chi.NewRouter()
|
||||
mux.Use(middleware.Logger)
|
||||
mux.Use(middleware.NoCache)
|
||||
|
||||
if enablePProf {
|
||||
mux.PathPrefix("/debug/").Handler(http.DefaultServeMux)
|
||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
mux.Mount("/debug", middleware.Profiler())
|
||||
}
|
||||
|
||||
_ = NewDebugService(node, mux)
|
||||
|
|
Loading…
Reference in New Issue