Skip to content

Commit

Permalink
Remove gorilla/mux router usages
Browse files Browse the repository at this point in the history
  • Loading branch information
syjn99 committed Oct 23, 2024
1 parent 38a6bae commit 3a64254
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 0 additions & 2 deletions beacon-chain/rpc/over/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ go_library(
"//network/httputil:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],
Expand All @@ -48,6 +47,5 @@ go_test(
"//testing/util:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
],
)
7 changes: 3 additions & 4 deletions beacon-chain/rpc/over/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strconv"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
Expand Down Expand Up @@ -40,7 +39,7 @@ func (s *Server) EstimatedActivation(w http.ResponseWriter, r *http.Request) {
return
}

rawId := mux.Vars(r)["validator_id"]
rawId := r.PathValue("validator_id")
valIndex, err := decodeValidatorId(st, rawId)
if err != nil {
httputil.WriteError(w, handleWrapError(err, "could not decode validator id from raw id", http.StatusBadRequest))
Expand Down Expand Up @@ -137,7 +136,7 @@ func (s *Server) GetEpochReward(w http.ResponseWriter, r *http.Request) {
defer span.End()

var requestedEpoch primitives.Epoch
epochId := mux.Vars(r)["epoch"]
epochId := r.PathValue("epoch")
curEpoch := slots.ToEpoch(s.GenesisTimeFetcher.CurrentSlot())

if epochId == "latest" {
Expand Down Expand Up @@ -181,7 +180,7 @@ func (s *Server) GetReserves(w http.ResponseWriter, r *http.Request) {
defer span.End()

// Retrieve beacon state
stateId := mux.Vars(r)["state_id"]
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
Expand Down
14 changes: 6 additions & 8 deletions beacon-chain/rpc/over/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/gorilla/mux"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestEstimatedActivation(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com//chronos/validator/estimated_activation/{validator_id}", nil)
request = mux.SetURLVars(request, map[string]string{"validator_id": tt.input})
request.SetPathValue("validator_id", tt.input)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand Down Expand Up @@ -170,7 +169,7 @@ func TestEstimatedActivation_NoPendingValidators(t *testing.T) {

t.Run("empty request", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com//chronos/validator/estimated_activation/{validator_id}", nil)
request = mux.SetURLVars(request, map[string]string{"validator_id": ""})
request.SetPathValue("validator_id", "")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand Down Expand Up @@ -227,7 +226,7 @@ func TestGetEpochReward(t *testing.T) {

request := httptest.NewRequest(
"GET", "/chronos/states/epoch_reward/{epoch}", nil)
request = mux.SetURLVars(request, map[string]string{"epoch": "100"})
request.SetPathValue("epoch", "100")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand All @@ -254,7 +253,7 @@ func TestGetEpochReward(t *testing.T) {

request := httptest.NewRequest(
"GET", "/chronos/states/epoch_reward/{epoch}", nil)
request = mux.SetURLVars(request, map[string]string{"epoch": "latest"})
request.SetPathValue("epoch", "latest")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand Down Expand Up @@ -284,7 +283,7 @@ func TestGetEpochReward(t *testing.T) {

request := httptest.NewRequest(
"GET", "/chronos/states/epoch_reward/{epoch}", nil)
request = mux.SetURLVars(request, map[string]string{"epoch": "100"})
request.SetPathValue("epoch", "100")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand Down Expand Up @@ -325,7 +324,7 @@ func TestGetReserves(t *testing.T) {
}
request := httptest.NewRequest(
"GET", "/over/v1/beacon/states/{state_id}/reserves", nil)
request = mux.SetURLVars(request, map[string]string{"state_id": "head"})
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand All @@ -351,7 +350,6 @@ func TestGetReserves(t *testing.T) {
}
request := httptest.NewRequest(
"GET", "/over/v1/beacon/states/{state_id}/reserves", nil)
request = mux.SetURLVars(request, map[string]string{})
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

Expand Down

0 comments on commit 3a64254

Please sign in to comment.