51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package storage
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
)
|
|
|
|
type URL struct {
|
|
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"`
|
|
Path string `bson:"path,omitempty" json:"path,omitempty"`
|
|
}
|
|
|
|
type StorageResource struct {
|
|
resource_model.AbstractResource
|
|
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"`
|
|
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
|
Size uint `bson:"size,omitempty" json:"size,omitempty"`
|
|
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
|
|
|
|
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"`
|
|
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"`
|
|
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"`
|
|
}
|
|
|
|
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
|
b, err := json.Marshal(j)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
return dma
|
|
}
|
|
|
|
func (dma *StorageResource) Serialize() map[string]interface{} {
|
|
var m map[string]interface{}
|
|
b, err := json.Marshal(dma)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, &m)
|
|
return m
|
|
}
|
|
|
|
func (d *StorageResource) GetAccessor() utils.Accessor {
|
|
data := New()
|
|
data.SetLogger(utils.STORAGE_RESOURCE)
|
|
return data
|
|
}
|