mirror of
https://github.com/juanfont/headscale.git
synced 2026-08-07 15:58:45 +09:00
8efa5ad1fe
Replace the gRPC client with the generated HTTP client across every command: locally over the unix socket without auth (matching the previous local gRPC socket), remotely over TLS with a Bearer API key. Output rendering and integration tests move to the HTTP client types; the transport changes, the assertions do not.
33 lines
844 B
Go
33 lines
844 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
clientv1 "github.com/juanfont/headscale/gen/client/v1"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(healthCmd)
|
|
}
|
|
|
|
var healthCmd = &cobra.Command{
|
|
Use: "health",
|
|
Short: "Check the health of the Headscale server",
|
|
Long: "Check the health of the Headscale server. This command will return an exit code of 0 if the server is healthy, or 1 if it is not.",
|
|
RunE: clientRunE(func(ctx context.Context, client *clientv1.ClientWithResponses, cmd *cobra.Command, args []string) error {
|
|
resp, err := client.HealthWithResponse(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("checking health: %w", err)
|
|
}
|
|
|
|
if resp.StatusCode() != http.StatusOK {
|
|
return apiError(resp.StatusCode(), resp.ApplicationproblemJSONDefault)
|
|
}
|
|
|
|
return printOutput(cmd, resp.JSON200, "")
|
|
}),
|
|
}
|