refactor: make SignedStorageLocationImpl props private, add NodeId getter, re-organize,
This commit is contained in:
parent
6c2ebb1152
commit
88c48aa996
|
@ -1,5 +1,7 @@
|
||||||
package interfaces
|
package interfaces
|
||||||
|
|
||||||
|
import "git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
|
|
||||||
//go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces
|
//go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces
|
||||||
|
|
||||||
type StorageLocationProvider interface {
|
type StorageLocationProvider interface {
|
||||||
|
@ -26,4 +28,5 @@ type StorageLocation interface {
|
||||||
}
|
}
|
||||||
type SignedStorageLocation interface {
|
type SignedStorageLocation interface {
|
||||||
String() string
|
String() string
|
||||||
|
NodeId() *encoding.NodeId
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,30 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
|
"go.uber.org/zap"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ msgpack.CustomDecoder = (*StorageLocationMap)(nil)
|
_ msgpack.CustomDecoder = (*StorageLocationMap)(nil)
|
||||||
|
_ msgpack.CustomEncoder = (*StorageLocationMap)(nil)
|
||||||
_ msgpack.CustomEncoder = (*StorageLocationMap)(nil)
|
_ interfaces.StorageLocation = (*StorageLocationImpl)(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 {
|
type StorageLocationImpl struct {
|
||||||
kind int
|
kind int
|
||||||
parts []string
|
parts []string
|
||||||
|
@ -90,30 +99,30 @@ func (s *StorageLocationImpl) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignedStorageLocationImpl struct {
|
type SignedStorageLocationImpl struct {
|
||||||
NodeID encoding.NodeId
|
nodeID *encoding.NodeId
|
||||||
Location StorageLocationImpl
|
location interfaces.StorageLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignedStorageLocation(NodeID encoding.NodeId, Location StorageLocationImpl) *SignedStorageLocationImpl {
|
func NewSignedStorageLocation(NodeID *encoding.NodeId, Location interfaces.StorageLocation) interfaces.SignedStorageLocation {
|
||||||
return &SignedStorageLocationImpl{
|
return &SignedStorageLocationImpl{
|
||||||
NodeID: NodeID,
|
nodeID: NodeID,
|
||||||
Location: Location,
|
location: Location,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssl *SignedStorageLocationImpl) String() string {
|
func (ssl *SignedStorageLocationImpl) String() string {
|
||||||
nodeString, _ := ssl.NodeID.ToString()
|
nodeString, _ := ssl.nodeID.ToString()
|
||||||
|
|
||||||
if nodeString == "" {
|
if nodeString == "" {
|
||||||
nodeString = "failed to decode node id"
|
nodeString = "failed to decode node id"
|
||||||
}
|
}
|
||||||
|
|
||||||
return "SignedStorageLocationImpl(" + ssl.Location.String() + ", " + nodeString + ")"
|
return "SignedStorageLocationImpl(" + ssl.location.String() + ", " + nodeString + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageLocationMap map[int]NodeStorage
|
func (ssl *SignedStorageLocationImpl) NodeId() *encoding.NodeId {
|
||||||
type NodeStorage map[string]NodeDetailsStorage
|
return ssl.nodeID
|
||||||
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()
|
temp, err := dec.DecodeUntypedMap()
|
||||||
|
|
Loading…
Reference in New Issue