43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package data
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
)
|
|
|
|
type DataResource struct {
|
|
resources.AbstractResource
|
|
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
|
DataType string `json:"datatype" bson:"datatype"`
|
|
Example string `json:"example" bson:"example" description:"base64 encoded data"`
|
|
}
|
|
|
|
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
|
b, err := json.Marshal(j)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
dma.AbstractResource.ObjDeserialize(j)
|
|
return dma
|
|
}
|
|
|
|
func (dma *DataResource) Serialize() map[string]interface{} {
|
|
var m map[string]interface{}
|
|
b, err := json.Marshal(dma)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
dma.AbstractResource.ObjSerialize()
|
|
return m
|
|
}
|
|
|
|
func (d *DataResource) GetAccessor() utils.Accessor {
|
|
data := &DataMongoAccessor{}
|
|
data.SetLogger(utils.DATACENTER_RESOURCE)
|
|
return data
|
|
}
|