From c0bc9fe78238a54a27d88c06f348d1c13beff3e4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 5 Dec 2024 09:57:40 +0100 Subject: [PATCH] updates --- go.mod | 2 +- ignite/pkg/cosmosfaucet/http.go | 49 +++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 63d5810471..623cc81291 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,6 @@ require ( github.com/golangci/golangci-lint v1.60.3 github.com/google/go-github/v48 v48.2.0 github.com/google/go-querystring v1.1.0 - github.com/gorilla/mux v1.8.1 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.2 github.com/iancoleman/strcase v0.3.0 @@ -287,6 +286,7 @@ require ( github.com/gordonklaus/ineffassign v0.1.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.4.2 // indirect diff --git a/ignite/pkg/cosmosfaucet/http.go b/ignite/pkg/cosmosfaucet/http.go index 8db36f3566..262161c576 100644 --- a/ignite/pkg/cosmosfaucet/http.go +++ b/ignite/pkg/cosmosfaucet/http.go @@ -3,7 +3,6 @@ package cosmosfaucet import ( "net/http" - "github.com/gorilla/mux" "github.com/rs/cors" "github.com/ignite/cli/v29/ignite/pkg/openapiconsole" @@ -12,23 +11,33 @@ import ( // ServeHTTP implements http.Handler to expose the functionality of Faucet.Transfer() via HTTP. // request/response payloads are compatible with the previous implementation at allinbits/cosmos-faucet. func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) { - router := mux.NewRouter() - - router. - Handle("/", cors.Default().Handler(http.HandlerFunc(f.faucetHandler))). - Methods(http.MethodPost, http.MethodOptions) - - router. - Handle("/info", cors.Default().Handler(http.HandlerFunc(f.faucetInfoHandler))). - Methods(http.MethodGet, http.MethodOptions) - - router. - HandleFunc("/", openapiconsole.Handler("Faucet", "openapi.yml")). - Methods(http.MethodGet) - - router. - HandleFunc("/openapi.yml", f.openAPISpecHandler). - Methods(http.MethodGet) - - router.ServeHTTP(w, r) + mux := http.NewServeMux() + + mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost || r.Method == http.MethodOptions { + f.faucetHandler(w, r) + } else if r.Method == http.MethodGet { + openapiconsole.Handler("Faucet", "openapi.yml")(w, r) + } else { + http.NotFound(w, r) + } + }))) + + mux.Handle("/info", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet || r.Method == http.MethodOptions { + f.faucetInfoHandler(w, r) + } else { + http.NotFound(w, r) + } + }))) + + mux.HandleFunc("/openapi.yml", func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet { + f.openAPISpecHandler(w, r) + } else { + http.NotFound(w, r) + } + }) + + mux.ServeHTTP(w, r) }