Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 5, 2024
1 parent 255bd74 commit c0bc9fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 29 additions & 20 deletions ignite/pkg/cosmosfaucet/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {

Check failure on line 17 in ignite/pkg/cosmosfaucet/http.go

View workflow job for this annotation

GitHub Actions / Lint Go code

ifElseChain: rewrite if-else to switch statement (gocritic)
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)
}

0 comments on commit c0bc9fe

Please sign in to comment.