From ef86db2bd06c6a2bf10856cbc5581fe73f90629a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 7 Jan 2024 04:33:40 -0500 Subject: [PATCH] refactor: need to export storage structs --- node/node.go | 8 ++++---- storage/storage.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/node/node.go b/node/node.go index 66b2bc7..8aef7e8 100644 --- a/node/node.go +++ b/node/node.go @@ -157,8 +157,8 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i } return locations, nil } -func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.storageLocationMap, error) { - locationMap := storage.newStorageLocationMap() +func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.StorageLocationMap, error) { + locationMap := storage.NewStorageLocationMap() bytes := n.cacheBucket.Get(hash.FullBytes()) if bytes == nil { @@ -187,8 +187,8 @@ func (n *NodeImpl) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding // Get or create the inner map for the specific type innerMap, exists := locationDb[location.Type()] if !exists { - innerMap = make(storage.nodeStorage, 1) - innerMap[nodeIdStr] = make(storage.nodeDetailsStorage, 1) + innerMap = make(storage.NodeStorage, 1) + innerMap[nodeIdStr] = make(storage.NodeDetailsStorage, 1) } // Create location map with new data diff --git a/storage/storage.go b/storage/storage.go index a916983..1eb0f0a 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -10,9 +10,9 @@ import ( ) var ( - _ msgpack.CustomDecoder = (*storageLocationMap)(nil) + _ msgpack.CustomDecoder = (*StorageLocationMap)(nil) - _ msgpack.CustomEncoder = (*storageLocationMap)(nil) + _ msgpack.CustomEncoder = (*StorageLocationMap)(nil) _ interfaces.StorageLocation = (*StorageLocationImpl)(nil) ) @@ -111,21 +111,21 @@ func (ssl *SignedStorageLocationImpl) String() string { return "SignedStorageLocationImpl(" + ssl.Location.String() + ", " + nodeString + ")" } -type storageLocationMap map[int]nodeStorage -type nodeStorage map[string]nodeDetailsStorage -type nodeDetailsStorage map[int]interface{} +type StorageLocationMap map[int]NodeStorage +type NodeStorage map[string]NodeDetailsStorage +type NodeDetailsStorage map[int]interface{} -func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { +func (s *StorageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { temp, err := dec.DecodeUntypedMap() if err != nil { return err } if *s == nil { - *s = make(map[int]nodeStorage) + *s = make(map[int]NodeStorage) } - tempMap, ok := interface{}(temp).(storageLocationMap) + tempMap, ok := interface{}(temp).(StorageLocationMap) if !ok { return fmt.Errorf("unexpected data format from msgpack decoding") } @@ -135,7 +135,7 @@ func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error { return nil } -func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error { +func (s StorageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error { // Create a temporary map to hold the encoded data tempMap := make(map[int]map[string]map[int]interface{}) @@ -152,6 +152,6 @@ func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error { return enc.Encode(tempMap) } -func newStorageLocationMap() storageLocationMap { - return storageLocationMap{} +func NewStorageLocationMap() StorageLocationMap { + return StorageLocationMap{} }