oc-lib/models/resources/resource.go
2024-07-19 13:15:51 +02:00

57 lines
1.6 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" required:"true" bson:"short_description" validate:"required"`
Description string `json:"description,omitempty" bson:"description"`
Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
Owner string `json:"owner" required:"true" bson:"owner" validate:"required"`
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
SourceUrl string `json:"source_url" required:"true" 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
}