config pb
This commit is contained in:
parent
070f2d063e
commit
53811538c0
@ -4,6 +4,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
@ -11,13 +12,12 @@ import (
|
||||
type LibDataEnum int
|
||||
|
||||
const (
|
||||
INVALID LibDataEnum = iota
|
||||
DATA_RESOURCE = utils.DATA_RESOURCE
|
||||
PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE
|
||||
STORAGE_RESOURCE = utils.STORAGE_RESOURCE
|
||||
DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE
|
||||
WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE
|
||||
WORKFLOW = utils.WORKFLOW
|
||||
INVALID LibDataEnum = iota
|
||||
DATA = resources.DATA
|
||||
PROCESSING = resources.PROCESSING
|
||||
STORAGE = resources.STORAGE
|
||||
DATACENTER = resources.DATACENTER
|
||||
WORKFLOW = resources.WORKFLOW
|
||||
)
|
||||
|
||||
func (d LibDataEnum) EnumIndex() int {
|
||||
@ -25,9 +25,8 @@ func (d LibDataEnum) EnumIndex() int {
|
||||
}
|
||||
|
||||
type LibData struct {
|
||||
DataResource utils.DBObject `bson:"data" json:"data"`
|
||||
Code int `bson:"code" json:"code"`
|
||||
Err string `bson:"error" json:"error"`
|
||||
Data utils.DBObject `bson:"data" json:"data"`
|
||||
Err error `bson:"error" json:"error"`
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
@ -41,30 +40,22 @@ func GetLogger() zerolog.Logger {
|
||||
}
|
||||
|
||||
func LoadOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
d, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
||||
return LibData{Data: d, Err: err}
|
||||
}
|
||||
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
set = model.Deserialize(set).Serialize()
|
||||
d, code, err := model.GetAccessor().UpdateOne(set, id)
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
d, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id)
|
||||
return LibData{Data: d, Err: err}
|
||||
}
|
||||
|
||||
func DeleteOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor().CopyOne(model.Deserialize(object))
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
d, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
||||
return LibData{Data: d, Err: err}
|
||||
}
|
||||
|
||||
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor().StoreOne(model.Deserialize(object))
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
d, err := model.GetAccessor().StoreOne(model.Deserialize(object))
|
||||
return LibData{Data: d, Err: err}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
type DataResource 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"`
|
||||
DataType string `json:"datatype" bson:"datatype"`
|
||||
Example string `json:"example" bson:"example" description:"base64 encoded data"`
|
||||
}
|
||||
|
||||
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
|
@ -9,8 +9,7 @@ import (
|
||||
|
||||
type DatacenterResource struct {
|
||||
resources.AbstractResource
|
||||
Owner string `bson:"owner" json:"owner" required:"true"`
|
||||
BookingPrice int `bson:"booking_price" json:"booking_price" required:"true"`
|
||||
BookingPrice int `bson:"booking_price" json:"booking_price"`
|
||||
|
||||
CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
|
||||
RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
|
||||
|
@ -18,12 +18,12 @@ type Resource interface {
|
||||
|
||||
type AbstractResource struct {
|
||||
utils.AbstractObject
|
||||
ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
|
||||
ShortDescription string `json:"short_description" 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"`
|
||||
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 {
|
||||
|
@ -1,41 +1,41 @@
|
||||
package graph
|
||||
|
||||
type Graph struct {
|
||||
Items map[string]GraphItem `bson:"items" json:"items" default:"{}" required:"true"`
|
||||
Links []GraphLink `bson:"links" json:"links" default:"{}" required:"true"`
|
||||
Items map[string]GraphItem `bson:"items" json:"items" default:"{}" validate:"required"`
|
||||
Links []GraphLink `bson:"links" json:"links" default:"{}" validate:"required"`
|
||||
}
|
||||
|
||||
type GraphItem struct {
|
||||
ID string `bson:"ID" json:"ID" required:"true"`
|
||||
Width float64 `bson:"width" json:"width" required:"true"`
|
||||
Height float64 `bson:"height" json:"height" required:"true"`
|
||||
Position Position `bson:"position" json:"position" required:"true"`
|
||||
ResourceID string `bson:"resource_id" json:"resource_id" required:"true"`
|
||||
ID string `bson:"ID" json:"ID" validate:"required"`
|
||||
Width float64 `bson:"width" json:"width" validate:"required"`
|
||||
Height float64 `bson:"height" json:"height" validate:"required"`
|
||||
Position Position `bson:"position" json:"position" validate:"required"`
|
||||
ResourceID string `bson:"resource_id" json:"resource_id" validate:"required"`
|
||||
}
|
||||
|
||||
type GraphLink struct {
|
||||
Source Position `bson:"source" json:"source" required:"true"`
|
||||
Destination Position `bson:"destination" json:"destination" required:"true"`
|
||||
Style GraphLinkStyle `bson:"style" json:"style" required:"true"`
|
||||
Source Position `bson:"source" json:"source" validate:"required"`
|
||||
Destination Position `bson:"destination" json:"destination" validate:"required"`
|
||||
Style GraphLinkStyle `bson:"style" json:"style" validate:"required"`
|
||||
}
|
||||
|
||||
type GraphLinkStyle struct {
|
||||
Color int64 `bson:"color" json:"color" required:"true"`
|
||||
Stroke float64 `bson:"stroke" json:"stroke" required:"true"`
|
||||
Color int64 `bson:"color" json:"color" validate:"required"`
|
||||
Stroke float64 `bson:"stroke" json:"stroke" validate:"required"`
|
||||
Tension float64 `bson:"tension" json:"tension"`
|
||||
HeadRadius float64 `bson:"head_radius" json:"head_radius"`
|
||||
DashWidth float64 `bson:"dash_width" json:"dash_width"`
|
||||
DashSpace float64 `bson:"dash_space" json:"dash_space"`
|
||||
EndArrow Position `bson:"end_arrow" json:"end_arrow"`
|
||||
StartArrow Position `bson:"start_arrow" json:"start_arrow"`
|
||||
ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" required:"true"`
|
||||
ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" required:"true"`
|
||||
ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" validate:"required"`
|
||||
ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" validate:"required"`
|
||||
StartArrowWidth float64 `bson:"start_arrow_style" json:"start_arrow_style"`
|
||||
EndArrowWidth float64 `bson:"end_arrow_style" json:"end_arrow_style"`
|
||||
}
|
||||
|
||||
type Position struct {
|
||||
ID string `json:"ID" required:"true"`
|
||||
X float64 `json:"x" required:"true"`
|
||||
Y float64 `json:"y" required:"true"`
|
||||
ID string `json:"ID" validate:"required"`
|
||||
X float64 `json:"x" validate:"required"`
|
||||
Y float64 `json:"y" validate:"required"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user