Refactored 800+ line main.go into clean, domain-separated files: - main.go (96 lines) - Entry point and command router only - types.go - Type definitions and data structures - client.go - HTTP client and request handling - cmd_kv.go - Key-value operations (get/put/delete) - cmd_meta.go - Resource metadata commands - cmd_user.go - User management commands - cmd_profile.go - Profile management - cmd_cluster.go - Cluster operations (members/health) - cmd_system.go - System commands (connect/auth/help) - utils.go - Shared utilities (parsing, colors, completion) No functional changes, pure reorganization for maintainability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func (c *KVSClient) handleMembers(args []string) {
|
|
respBody, status, err := c.doRequest("GET", "/members/", nil)
|
|
if err != nil {
|
|
fmt.Println(red("Error:"), err)
|
|
return
|
|
}
|
|
|
|
if status != 200 {
|
|
fmt.Println(red("Error:"), string(respBody))
|
|
return
|
|
}
|
|
|
|
var members []Member
|
|
if err := json.Unmarshal(respBody, &members); err != nil {
|
|
fmt.Println(red("Error parsing response:"), err)
|
|
return
|
|
}
|
|
|
|
if len(members) == 0 {
|
|
fmt.Println(yellow("No cluster members"))
|
|
return
|
|
}
|
|
|
|
fmt.Println(cyan("Cluster Members:"))
|
|
for _, m := range members {
|
|
lastSeen := time.UnixMilli(m.LastSeen).Format(time.RFC3339)
|
|
fmt.Printf(" • %s (%s) - Last seen: %s\n", m.ID, m.Address, lastSeen)
|
|
}
|
|
}
|
|
|
|
func (c *KVSClient) handleHealth(args []string) {
|
|
respBody, status, err := c.doRequest("GET", "/health", nil)
|
|
if err != nil {
|
|
fmt.Println(red("Error:"), err)
|
|
return
|
|
}
|
|
|
|
if status != 200 {
|
|
fmt.Println(red("Service unhealthy"))
|
|
return
|
|
}
|
|
|
|
var health map[string]interface{}
|
|
if err := json.Unmarshal(respBody, &health); err != nil {
|
|
fmt.Println(red("Error parsing response:"), err)
|
|
return
|
|
}
|
|
|
|
fmt.Println(green("Service Status:"))
|
|
for k, v := range health {
|
|
fmt.Printf(" %s: %v\n", cyan(k), v)
|
|
}
|
|
}
|