oc-lib/models/resources/data/data.go

40 lines
925 B
Go

package data
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type DataResource struct {
utils.AbstractResource
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
DataType string `json:"datatype,omitempty" bson:"datatype,omitempty"`
Example string `json:"example,omitempty" bson:"example,omitempty" 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)
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, &m)
return m
}
func (d *DataResource) GetAccessor() utils.Accessor {
data := &DataMongoAccessor{}
data.SetLogger(utils.DATACENTER_RESOURCE)
return data
}