diff --git a/consts/consts.go b/consts/consts.go index 55eefec..dd9f224 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -1,31 +1,26 @@ package consts const ( - REDUNDANCY_REP = "rep" - REDUNDANCY_EC = "ec" -) - -const ( - IPFS_STATE_OK = "OK" + IPFSStateOK = "OK" - STORAGE_DIRECTORY_STATE_OK = "OK" + StorageDirectoryStateOK = "OK" - NODE_STATE_NORMAL = "Normal" - NODE_STATE_UNAVAILABLE = "Unavailable" + NodeStateNormal = "Normal" + NodeStateUnavailable = "Unavailable" ) const ( - OBJECT_STATE_NORMAL = "Normal" - OBJECT_STATE_DELETED = "Deleted" + ObjectStateNormal = "Normal" + ObjectStateDeleted = "Deleted" ) const ( - STORAGE_OBJECT_STATE_NORMAL = "Normal" - STORAGE_OBJECT_STATE_DELETED = "Deleted" - STORAGE_OBJECT_STATE_OUTDATED = "Outdated" + StorageObjectStateNormal = "Normal" + StorageObjectStateDeleted = "Deleted" + StorageObjectStateOutdated = "Outdated" ) const ( - CACHE_STATE_PINNED = "Pinned" - CACHE_STATE_TEMP = "Temp" + CacheStatePinned = "Pinned" + CacheStateTemp = "Temp" ) diff --git a/consts/errorcode/error_code.go b/consts/errorcode/error_code.go index 2855c9a..4c7bc59 100644 --- a/consts/errorcode/error_code.go +++ b/consts/errorcode/error_code.go @@ -1,8 +1,8 @@ package errorcode const ( - OK = "OK" - OPERATION_FAILED = "OPERATION_FAILED" - - TASK_NOT_FOUND = "TASK_NOT_FOUND" + OK = "OK" + OperationFailed = "OperationFailed" + BadArgument = "BadArgument" + TaskNotFound = "TaskNotFound" ) diff --git a/models/models.go b/models/models.go new file mode 100644 index 0000000..10d8a61 --- /dev/null +++ b/models/models.go @@ -0,0 +1,55 @@ +package models + +/// TODO 将分散在各处的公共结构体定义集中到这里来 + +const ( + RedundancyRep = "rep" + RedundancyEC = "ec" +) + +type RedundancyConfigTypes interface{} +type RedundancyConfigTypesConst interface { + RepRedundancyConfig | ECRedundancyConfig +} +type RepRedundancyConfig struct { + RepCount int `json:"repCount"` +} + +type ECRedundancyConfig struct { +} + +type RedundancyDataTypes interface{} +type RedundancyDataTypesConst interface { + RepRedundancyData | ECRedundancyData +} +type RepRedundancyData struct { + FileHash string `json:"fileHash"` +} + +func NewRedundancyRepData(fileHash string) RepRedundancyData { + return RepRedundancyData{ + FileHash: fileHash, + } +} + +type ECRedundancyData struct { + Blocks []ObjectBlock `json:"blocks"` +} + +func NewECRedundancyData(blocks []ObjectBlock) ECRedundancyData { + return ECRedundancyData{ + Blocks: blocks, + } +} + +type ObjectBlock struct { + Index int `json:"index"` + FileHash string `json:"fileHash"` +} + +func NewObjectBlock(index int, fileHash string) ObjectBlock { + return ObjectBlock{ + Index: index, + FileHash: fileHash, + } +}