fix: json marshaling

This commit is contained in:
yusing
2025-04-26 01:31:22 +08:00
parent db6fc65876
commit 03d609e4e1
8 changed files with 28 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ package proxmox
import (
"context"
"encoding/json"
"fmt"
"github.com/luthermonson/go-proxmox"
@@ -45,9 +46,8 @@ func (c *Client) Name() string {
return c.Cluster.Name
}
// MarshalMap implements pool.Object
func (c *Client) MarshalMap() map[string]any {
return map[string]any{
func (c *Client) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"version": c.Version,
"cluster": map[string]any{
"name": c.Cluster.Name,
@@ -56,7 +56,7 @@ func (c *Client) MarshalMap() map[string]any {
"nodes": c.Cluster.Nodes,
"quorate": c.Cluster.Quorate,
},
}
})
}
func (c *Client) NumNodes() int {

View File

@@ -2,6 +2,7 @@ package proxmox
import (
"context"
"encoding/json"
"fmt"
"strings"
@@ -38,11 +39,11 @@ func (n *Node) String() string {
return fmt.Sprintf("%s (%s)", n.name, n.id)
}
func (n *Node) MarshalMap() map[string]any {
return map[string]any{
func (n *Node) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"name": n.name,
"id": n.id,
}
})
}
func (n *Node) Get(ctx context.Context, path string, v any) error {