oc-lib/models/resources/data/data.go
2024-07-19 09:32:58 +02:00

45 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 Data struct {
resources.AbstractResource
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
DataType string `json:"datatype" required:"true" bson:"datatype"`
Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"`
}
func (dma *Data) 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 *Data) 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 *Data) GetType() resources.ResourceType {
return resources.DATA
}
func (d *Data) GetAccessor() utils.Accessor {
data := &DataMongoAccessor{}
data.SetLogger(resources.DATA)
return data
}