Skip to content

Commit

Permalink
feat: allow changing rest server port address
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed May 4, 2022
1 parent 7ddd14c commit eb72871
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
package cmd

import (
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"net/http"
"okp4/cosmos-faucet/rest"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"net/http"
"okp4/cosmos-faucet/rest"
)

const (
FlagAddress = "address"
)

// NewStartCommand returns a CLI command to start the REST api allowing to send tokens.
func NewStartCommand() *cobra.Command {
startCmd := &cobra.Command{
Use: "start",
Short: "Start the REST api",
RunE: func(cmd *cobra.Command, args []string) error {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/send/{address}", rest.NewSendRequestHandlerFn(config)).Methods("GET")

return http.ListenAndServe(":10000", router)
},
}

return startCmd
var addr string

startCmd := &cobra.Command{
Use: "start",
Short: "Start the REST api",
RunE: func(cmd *cobra.Command, args []string) error {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/send/{address}", rest.NewSendRequestHandlerFn(config)).Methods("GET")

return http.ListenAndServe(addr, router)
},
}

startCmd.Flags().StringVar(&addr, FlagAddress, ":8080", "rest api address")

return startCmd
}

func init() {
rootCmd.AddCommand(NewStartCommand())
rootCmd.AddCommand(NewStartCommand())
}

0 comments on commit eb72871

Please sign in to comment.