error-pages/internal/cli/healthcheck/command.go
2023-02-23 21:49:45 +04:00

37 lines
815 B
Go

// Package healthcheck contains CLI `healthcheck` command implementation.
package healthcheck
import (
"errors"
"math"
"github.com/urfave/cli/v2"
"gh.tarampamp.am/error-pages/internal/cli/shared"
)
type checker interface {
Check(port uint16) error
}
// NewCommand creates `healthcheck` command.
func NewCommand(checker checker) *cli.Command {
return &cli.Command{
Name: "healthcheck",
Aliases: []string{"chk", "health", "check"},
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")
}
return checker.Check(uint16(port))
},
Flags: []cli.Flag{
shared.ListenPortFlag,
},
}
}