omitempty is not null
This commit is contained in:
68
~/.vscode-root/User/History/32396225/P6hm.go
Normal file
68
~/.vscode-root/User/History/32396225/P6hm.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package oclib
|
||||
|
||||
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/utils"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
func (d LibDataEnum) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
||||
|
||||
type LibData struct {
|
||||
Data utils.DBObject `bson:"data" json:"data"`
|
||||
Code int `bson:"code" json:"code"`
|
||||
Err string `bson:"error" json:"error"`
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
logs.SetAppName(appName)
|
||||
logs.SetLogger(logs.CreateLogger("main", ""))
|
||||
mongo.MONGOService.Init(models.GetModelsNames(), GetConfig())
|
||||
}
|
||||
|
||||
func GetLogger() zerolog.Logger {
|
||||
return logs.GetLogger()
|
||||
}
|
||||
|
||||
func LoadOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func DeleteOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
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{Data: 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{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
68
~/.vscode-root/User/History/32396225/YMBZ.go
Normal file
68
~/.vscode-root/User/History/32396225/YMBZ.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package oclib
|
||||
|
||||
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/utils"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
func (d LibDataEnum) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
||||
|
||||
type LibData struct {
|
||||
Data utils.DBObject `bson:"data" json:"data"`
|
||||
Code int `bson:"code" json:"code"`
|
||||
Err string `bson:"error" json:"error"`
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
logs.SetAppName(appName)
|
||||
logs.SetLogger(logs.CreateLogger("main", ""))
|
||||
mongo.MONGOService.Init(models.GetModelsNames(), GetConfig())
|
||||
}
|
||||
|
||||
func GetLogger() zerolog.Logger {
|
||||
return logs.GetLogger()
|
||||
}
|
||||
|
||||
func LoadOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func DeleteOne(collection LibDataEnum, id string) LibData {
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
||||
return LibData{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
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{Data: 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{Data: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
1
~/.vscode-root/User/History/32396225/entries.json
Normal file
1
~/.vscode-root/User/History/32396225/entries.json
Normal file
@@ -0,0 +1 @@
|
||||
{"version":1,"resource":"file:///home/mr/Documents/OC/oc-lib/entrypoint.go","entries":[{"id":"P6hm.go","timestamp":1721635650550},{"id":"YMBZ.go","timestamp":1721635871948}]}
|
||||
Reference in New Issue
Block a user