refactor: make SignedStorageLocationImpl props private, add NodeId getter, re-organize,

This commit is contained in:
Derrick Hammer 2024-01-09 07:01:19 -05:00
parent 6c2ebb1152
commit 88c48aa996
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 26 additions and 14 deletions

View File

@ -1,5 +1,7 @@
package interfaces
import "git.lumeweb.com/LumeWeb/libs5-go/encoding"
//go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces
type StorageLocationProvider interface {
@ -26,4 +28,5 @@ type StorageLocation interface {
}
type SignedStorageLocation interface {
String() string
NodeId() *encoding.NodeId
}

View File

@ -1,21 +1,30 @@
package storage
import (
"bytes"
"fmt"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"github.com/vmihailenco/msgpack/v5"
"go.uber.org/zap"
"strconv"
"sync"
"time"
)
var (
_ msgpack.CustomDecoder = (*StorageLocationMap)(nil)
_ msgpack.CustomEncoder = (*StorageLocationMap)(nil)
_ interfaces.StorageLocation = (*StorageLocationImpl)(nil)
_ interfaces.StorageLocationProvider = (*StorageLocationProviderImpl)(nil)
_ interfaces.SignedStorageLocation = (*SignedStorageLocationImpl)(nil)
)
type StorageLocationMap map[int]NodeStorage
type NodeStorage map[string]NodeDetailsStorage
type NodeDetailsStorage map[int]interface{}
type StorageLocationImpl struct {
kind int
parts []string
@ -90,30 +99,30 @@ func (s *StorageLocationImpl) String() string {
}
type SignedStorageLocationImpl struct {
NodeID encoding.NodeId
Location StorageLocationImpl
nodeID *encoding.NodeId
location interfaces.StorageLocation
}
func NewSignedStorageLocation(NodeID encoding.NodeId, Location StorageLocationImpl) *SignedStorageLocationImpl {
func NewSignedStorageLocation(NodeID *encoding.NodeId, Location interfaces.StorageLocation) interfaces.SignedStorageLocation {
return &SignedStorageLocationImpl{
NodeID: NodeID,
Location: Location,
nodeID: NodeID,
location: Location,
}
}
func (ssl *SignedStorageLocationImpl) String() string {
nodeString, _ := ssl.NodeID.ToString()
nodeString, _ := ssl.nodeID.ToString()
if nodeString == "" {
nodeString = "failed to decode node id"
}
return "SignedStorageLocationImpl(" + ssl.Location.String() + ", " + nodeString + ")"
return "SignedStorageLocationImpl(" + ssl.location.String() + ", " + nodeString + ")"
}
type StorageLocationMap map[int]NodeStorage
type NodeStorage map[string]NodeDetailsStorage
type NodeDetailsStorage map[int]interface{}
func (ssl *SignedStorageLocationImpl) NodeId() *encoding.NodeId {
return ssl.nodeID
}
func (s *StorageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error {
temp, err := dec.DecodeUntypedMap()