51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
)
|
|
|
|
type URL struct {
|
|
Protocol string `bson:"protocol" json:"protocol"`
|
|
Path string `bson:"path" json:"path"`
|
|
}
|
|
|
|
type Storage struct {
|
|
resources.AbstractResource
|
|
|
|
Capacity uint `bson:"capacity,omitempty" json:"capacity,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"`
|
|
BookingPrice uint `bson:"booking_price,omitempty" json:"booking_price,omitempty"`
|
|
}
|
|
|
|
func (dma *Storage) 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 *Storage) Serialize() map[string]interface{} {
|
|
var m map[string]interface{}
|
|
b, err := json.Marshal(dma)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
return m
|
|
}
|
|
|
|
func (d *Storage) GetAccessor() utils.Accessor {
|
|
data := &StorageMongoAccessor{}
|
|
data.SetLogger(resources.STORAGE)
|
|
return data
|
|
}
|