error-pages/internal/cli/healthcheck/command.go

37 lines
815 B
Go
Raw Normal View History

2021-09-29 15:38:50 +00:00
// Package healthcheck contains CLI `healthcheck` command implementation.
package healthcheck
import (
2023-01-29 10:54:56 +00:00
"errors"
"math"
2021-09-29 15:38:50 +00:00
2023-01-29 10:54:56 +00:00
"github.com/urfave/cli/v2"
2022-11-01 21:13:03 +00:00
"gh.tarampamp.am/error-pages/internal/cli/shared"
2021-09-29 15:38:50 +00:00
)
type checker interface {
Check(port uint16) error
}
// NewCommand creates `healthcheck` command.
2023-01-29 10:54:56 +00:00
func NewCommand(checker checker) *cli.Command {
return &cli.Command{
Name: "healthcheck",
2021-09-29 15:38:50 +00:00
Aliases: []string{"chk", "health", "check"},
2023-01-29 10:54:56 +00:00
Usage: "Health checker for the HTTP server. Use case - docker healthcheck",
Action: func(c *cli.Context) error {
var port = c.Uint(shared.ListenPortFlag.Name)
if port <= 0 || port > math.MaxUint16 {
return errors.New("port value out of range")
}
2021-09-29 15:38:50 +00:00
2023-01-29 10:54:56 +00:00
return checker.Check(uint16(port))
2021-09-29 15:38:50 +00:00
},
2023-01-29 10:54:56 +00:00
Flags: []cli.Flag{
shared.ListenPortFlag,
2021-09-29 15:38:50 +00:00
},
}
}