nice shortcut on resource

This commit is contained in:
mr 2024-07-31 16:56:30 +02:00
parent 51f3a320b3
commit ad455e0e3a
2 changed files with 39 additions and 1 deletions

View File

@ -89,7 +89,7 @@ func (m *MongoDB) createClient(MongoURL string) error {
if err = mngoClient.Ping(MngoCtx, nil); err != nil {
mngoClient = nil
return errors.New("Mongodb connect " + MongoURL + ":" + "err")
return errors.New("Mongodb ping " + MongoURL + ":" + "err")
}
return nil
}

View File

@ -20,6 +20,44 @@ type AbstractResource struct {
ResourceModel *ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"`
}
func (abs *AbstractResource) GetModelValue(key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil
}
if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil
}
return abs.ResourceModel.Model[key].Value
}
func (abs *AbstractResource) GetModelType(key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil
}
if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil
}
return abs.ResourceModel.Model[key].Type
}
func (abs *AbstractResource) GetModelKeys() []string {
keys := make([]string, 0)
for k := range abs.ResourceModel.Model {
keys = append(keys, k)
}
return keys
}
func (abs *AbstractResource) GetModelReadOnly(key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil
}
if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil
}
return abs.ResourceModel.Model[key].ReadOnly
}
type Model struct {
Type string `json:"type,omitempty" bson:"type,omitempty"`
Value interface{} `json:"value,omitempty" bson:"value,omitempty"`