Add mcproxyctl CLI for gRPC admin API

Introduces a new command-line tool for managing mc-proxy via the gRPC
admin API over Unix socket. Commands include route and firewall rule
CRUD operations, health checks, and status queries.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 08:09:13 -07:00
parent f24fa2a2b0
commit 666d55018c
8 changed files with 410 additions and 1 deletions

42
cmd/mcproxyctl/status.go Normal file
View File

@@ -0,0 +1,42 @@
package main
import (
"context"
"fmt"
"time"
"github.com/spf13/cobra"
)
func statusCmd() *cobra.Command {
return &cobra.Command{
Use: "status",
Short: "Show server status",
Long: "Show server status including version, uptime, and listener information.",
RunE: func(cmd *cobra.Command, args []string) error {
client := clientFromContext(cmd.Context())
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
defer cancel()
status, err := client.GetStatus(ctx)
if err != nil {
return fmt.Errorf("getting status: %w", err)
}
fmt.Printf("mc-proxy %s\n", status.Version)
if !status.StartedAt.IsZero() {
uptime := time.Since(status.StartedAt).Truncate(time.Second)
fmt.Printf("uptime: %s\n", uptime)
}
fmt.Printf("connections: %d\n", status.TotalConnections)
fmt.Println()
for _, ls := range status.Listeners {
fmt.Printf(" %s routes=%d active=%d\n", ls.Addr, ls.RouteCount, ls.ActiveConnections)
}
return nil
},
}
}