Skip to content

Commit

Permalink
chore: move the ping command to handler (goharbor#285)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Tang <jmtangcs@gmail.com>
  • Loading branch information
Standing-Man committed Feb 5, 2025
1 parent 1caba12 commit 3b4b37f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/harbor/root/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ func HealthCommand() *cobra.Command {
Use: "health",
Short: "Get the health status of Harbor components",
RunE: func(cmd *cobra.Command, args []string) error {
err := api.Ping()
if err != nil {
return err
}
status, err := api.GetHealth()
if err != nil {
return err
Expand Down
23 changes: 23 additions & 0 deletions pkg/api/ping_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package api

import (
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/ping"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/sirupsen/logrus"
)

func Ping() error {
ctx, client, err := utils.ContextWithClient()
if err != nil {
logrus.Errorf("failed to get client: %v", err)
return err
}

_, err = client.Ping.GetPing(ctx, &ping.GetPingParams{})
if err != nil {
logrus.Errorf("failed to ping the server: %v", err)
return err
}

return nil
}

0 comments on commit 3b4b37f

Please sign in to comment.