fix --port flag shorthand in test endpoint; error handling (#67)

This commit is contained in:
Michael Quigley 2022-09-27 15:13:17 -04:00
parent 4e08dd379c
commit 222a494dbf
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -38,10 +38,13 @@ func newTestEndpointCommand() *testEndpointCommand {
command := &testEndpointCommand{cmd: cmd}
var err error
if command.t, err = template.ParseFS(endpoint_ui.FS, "index.gohtml"); err != nil {
if !panicInstead {
showError("unable to parse index template", err)
}
panic(err)
}
cmd.Flags().StringVarP(&command.address, "address", "a", "0.0.0.0", "The address for the HTTP listener")
cmd.Flags().Uint16VarP(&command.port, "port", "p", 9090, "The port for the HTTP listener")
cmd.Flags().Uint16VarP(&command.port, "port", "P", 9090, "The port for the HTTP listener")
cmd.Run = command.run
return command
}
@ -49,6 +52,9 @@ func newTestEndpointCommand() *testEndpointCommand {
func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) {
http.HandleFunc("/", cmd.serveIndex)
if err := http.ListenAndServe(fmt.Sprintf("%v:%d", cmd.address, cmd.port), nil); err != nil {
if !panicInstead {
showError("unable to start http listener", err)
}
panic(err)
}
}