45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package data
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
)
|
|
|
|
/*
|
|
* DataResource is a struct that represents a data resource
|
|
* it defines the resource data
|
|
*/
|
|
type DataResource struct {
|
|
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
|
resource_model.WebResource
|
|
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the 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(caller *tools.HTTPCaller) utils.Accessor {
|
|
data := New() // Create a new instance of the accessor
|
|
data.Init(tools.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
|
return data
|
|
}
|