57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package resources
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
)
|
|
|
|
// AbstractResource is the struct containing all of the attributes commons to all ressources
|
|
|
|
// Resource is the interface to be implemented by all classes inheriting from Resource to have the same behavior
|
|
|
|
//http://www.inanzzz.com/index.php/post/wqbs/a-basic-usage-of-int-and-string-enum-types-in-golang
|
|
|
|
type Resource interface {
|
|
GetType() utils.DataType
|
|
}
|
|
|
|
type AbstractResource struct {
|
|
utils.AbstractObject
|
|
ShortDescription string `json:"short_description" bson:"short_description" validate:"required"`
|
|
Description string `json:"description,omitempty" bson:"description"`
|
|
Logo string `json:"logo" bson:"logo" validate:"required"`
|
|
Owner string `json:"owner" bson:"owner" validate:"required"`
|
|
OwnerLogo string `json:"owner_logo" bson:"owner_logo"`
|
|
SourceUrl string `json:"source_url" bson:"source_url" validate:"required"`
|
|
}
|
|
|
|
func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource {
|
|
b, err := json.Marshal(j)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
dma.AbstractObject.ObjDeserialize(j)
|
|
return dma
|
|
}
|
|
|
|
func (dma *AbstractResource) ObjSerialize() map[string]interface{} {
|
|
var m map[string]interface{}
|
|
b, err := json.Marshal(dma)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
json.Unmarshal(b, dma)
|
|
dma.AbstractObject.ObjSerialize()
|
|
return m
|
|
}
|
|
|
|
func (r *AbstractResource) GetID() string {
|
|
return r.UUID
|
|
}
|
|
|
|
func (r *AbstractResource) GetName() string {
|
|
return r.Name
|
|
}
|