Skip to content

Commit

Permalink
Add a custom json marshaller for Nodes
Browse files Browse the repository at this point in the history
That fixes the long-standing issue of recursion errors in log messages.
  • Loading branch information
aduffeck committed Jul 31, 2024
1 parent fac559e commit e459139
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"hash"
"hash/adler32"
Expand Down Expand Up @@ -172,6 +173,26 @@ func New(spaceID, id, parentID, name string, blobsize int64, blobID string, t pr
}
}

func (n *Node) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Name string `json:"name"`
ID string `json:"id"`
SpaceID string `json:"spaceID"`
ParentID string `json:"parentID"`
BlobID string `json:"blobID"`
BlobSize int64 `json:"blobSize"`
Exists bool `json:"exists"`
}{
Name: n.Name,
ID: n.ID,
SpaceID: n.SpaceID,
ParentID: n.ParentID,
BlobID: n.BlobID,
BlobSize: n.Blobsize,
Exists: n.Exists,
})
}

// Type returns the node's resource type
func (n *Node) Type(ctx context.Context) provider.ResourceType {
if n.nodeType != nil {
Expand Down

0 comments on commit e459139

Please sign in to comment.