generated from okp4/template-go
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow changing rest server port address
- Loading branch information
Showing
1 changed file
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |