oc-lib/models/resources/resource.go

64 lines
1.7 KiB
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package resources
// 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 ResourceType int
const (
INVALID ResourceType = iota
DATA
PROCESSING
STORAGE
DATACENTER
WORKFLOW
)
var str = [...]string{
"invalid",
"data",
"processing",
"storage",
"datacenter",
"workflow",
}
2024-07-18 15:15:01 +02:00
func FromInt(i int) string {
return str[i]
}
func (d ResourceType) String() string {
return str[d]
}
// EnumIndex - Creating common behavior-give the type a EnumIndex functio
func (d ResourceType) EnumIndex() int {
return int(d)
2024-07-18 11:51:12 +02:00
}
type Resource interface {
GetType() ResourceType
}
type AbstractResource struct {
2024-07-19 09:32:58 +02:00
Uuid string `json:"uuid" required:"true" bson:"uuid" validate:"required"`
Name string `json:"name" required:"true" bson:"name" validate:"required"`
ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
2024-07-18 11:51:12 +02:00
Description string `json:"description,omitempty" bson:"description"`
2024-07-19 09:32:58 +02:00
Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
Owner string `json:"owner" required:"true" bson:"owner" validate:"required"`
2024-07-18 11:51:12 +02:00
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
2024-07-19 09:32:58 +02:00
SourceUrl string `json:"source_url" required:"true" bson:"source_url" validate:"required"`
2024-07-18 11:51:12 +02:00
}
func (r *AbstractResource) GetID() string {
return r.Uuid
}
func (r *AbstractResource) GetName() string {
return r.Name
}