Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package cosmosfaucet
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/rs/cors"
|
|
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/openapiconsole"
|
|
)
|
|
|
|
// 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) {
|
|
mux := http.NewServeMux()
|
|
|
|
mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case r.Method == http.MethodPost || r.Method == http.MethodOptions:
|
|
f.faucetHandler(w, r)
|
|
case r.Method == http.MethodGet:
|
|
openapiconsole.Handler("Faucet", "openapi.yml")(w, r)
|
|
default:
|
|
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)
|
|
}
|