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

35 lines
852 B
Go
Raw Permalink Normal View History

2021-09-29 15:38:50 +00:00
package healthcheck
import (
2024-07-03 14:12:13 +00:00
"context"
"fmt"
2021-09-29 15:38:50 +00:00
2024-07-03 14:12:13 +00:00
"github.com/urfave/cli/v3"
2022-11-01 21:13:03 +00:00
"gh.tarampamp.am/error-pages/internal/cli/shared"
2024-07-03 14:12:13 +00:00
"gh.tarampamp.am/error-pages/internal/logger"
2021-09-29 15:38:50 +00:00
)
type checker interface {
2024-07-03 14:12:13 +00:00
Check(ctx context.Context, baseURL string) error
2021-09-29 15:38:50 +00:00
}
// NewCommand creates `healthcheck` command.
2024-07-03 14:12:13 +00:00
func NewCommand(_ *logger.Logger, checker checker) *cli.Command {
var portFlag = shared.ListenPortFlag
portFlag.Usage = "TCP port number with the HTTP server to check"
2023-01-29 10:54:56 +00:00
return &cli.Command{
Name: "healthcheck",
2021-09-29 15:38:50 +00:00
Aliases: []string{"chk", "health", "check"},
2024-07-03 14:12:13 +00:00
Usage: "Health checker for the HTTP server. The use case - docker health check",
Action: func(ctx context.Context, c *cli.Command) error {
return checker.Check(ctx, fmt.Sprintf("http://127.0.0.1:%d", c.Uint(portFlag.Name)))
2021-09-29 15:38:50 +00:00
},
2023-01-29 10:54:56 +00:00
Flags: []cli.Flag{
2024-07-03 14:12:13 +00:00
&portFlag,
2021-09-29 15:38:50 +00:00
},
}
}