Report fields added
This commit is contained in:
26
persist.go
26
persist.go
@@ -40,13 +40,20 @@ func NewPersist(props *PersistProps) *Persist {
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
var persistOriginal *Persist
|
||||
|
||||
var deferedFuncs map[string]any = make(map[string]any, 0)
|
||||
|
||||
var persist any
|
||||
|
||||
type InitReport struct {
|
||||
Fields []string
|
||||
}
|
||||
|
||||
func (report *InitReport) AddField(field string) {
|
||||
report.Fields = append(report.Fields, field)
|
||||
}
|
||||
|
||||
type InitProps struct {
|
||||
MongoSysDb string
|
||||
}
|
||||
@@ -80,22 +87,27 @@ func Init(props *InitProps) {
|
||||
|
||||
// 1. Copy all existing fields
|
||||
for i := 0; i < origType.NumField(); i++ {
|
||||
log.Printf("Add existing field: %v", origType.Field(i))
|
||||
// log.Printf("Add existing field: %v", origType.Field(i))
|
||||
fields = append(fields, origType.Field(i))
|
||||
}
|
||||
|
||||
client := mongo.GetMongoClient()
|
||||
|
||||
report := &InitReport{}
|
||||
|
||||
// Take system_collection from structful and build the calls.
|
||||
for _, col := range scol {
|
||||
BuildInsertOne(col)
|
||||
BuildFindOne(col)
|
||||
BuildFind(col)
|
||||
BuildGetOne(col)
|
||||
BuildDeleteOne(col)
|
||||
BuildInsertOne(col, report)
|
||||
BuildFindOne(col, report)
|
||||
BuildFind(col, report)
|
||||
BuildGetOne(col, report)
|
||||
BuildDeleteOne(col, report)
|
||||
|
||||
client.AddDefinition(col)
|
||||
}
|
||||
|
||||
log.Printf("Fields Registered: %v", report.Fields)
|
||||
|
||||
// 3. Create the new struct type
|
||||
newStructType := reflect.StructOf(fields)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"git.gsuntres.com/general/mongo"
|
||||
)
|
||||
|
||||
func BuildDeleteOne(col map[string]any) {
|
||||
func BuildDeleteOne(col map[string]any, report *InitReport) {
|
||||
name := col["_name"].(string)
|
||||
singular := col["singular"].(string)
|
||||
|
||||
@@ -36,6 +36,8 @@ func BuildDeleteOne(col map[string]any) {
|
||||
isSystem = v.(bool)
|
||||
}
|
||||
|
||||
report.AddField(deleteOneName)
|
||||
|
||||
mc := mongo.GetMongoClient()
|
||||
|
||||
// we defer function's implementation until we create the actual struct
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"git.gsuntres.com/general/mongo"
|
||||
)
|
||||
|
||||
func BuildFind(col map[string]any) {
|
||||
func BuildFind(col map[string]any, report *InitReport) {
|
||||
name := col["_name"].(string)
|
||||
plural := col["plural"].(string)
|
||||
|
||||
@@ -40,6 +40,8 @@ func BuildFind(col map[string]any) {
|
||||
isSystem = v.(bool)
|
||||
}
|
||||
|
||||
report.AddField(funcName)
|
||||
|
||||
mc := mongo.GetMongoClient()
|
||||
|
||||
// we defer function's implementation until we create the actual struct
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"git.gsuntres.com/general/mongo"
|
||||
)
|
||||
|
||||
func BuildFindOne(col map[string]any) {
|
||||
func BuildFindOne(col map[string]any, report *InitReport) {
|
||||
name := col["_name"].(string)
|
||||
singular := col["singular"].(string)
|
||||
|
||||
@@ -39,6 +39,8 @@ func BuildFindOne(col map[string]any) {
|
||||
isSystem = v.(bool)
|
||||
}
|
||||
|
||||
report.AddField(funcName)
|
||||
|
||||
mc := mongo.GetMongoClient()
|
||||
|
||||
// we defer function's implementation until we create the actual struct
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"git.gsuntres.com/general/mongo"
|
||||
)
|
||||
|
||||
func BuildGetOne(col map[string]any) {
|
||||
func BuildGetOne(col map[string]any, report *InitReport) {
|
||||
name := col["_name"].(string)
|
||||
singular := col["singular"].(string)
|
||||
|
||||
@@ -39,6 +39,8 @@ func BuildGetOne(col map[string]any) {
|
||||
isSystem = v.(bool)
|
||||
}
|
||||
|
||||
report.AddField(funcName)
|
||||
|
||||
mc := mongo.GetMongoClient()
|
||||
|
||||
// we defer function's implementation until we create the actual struct
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"git.gsuntres.com/general/mongo"
|
||||
)
|
||||
|
||||
func BuildInsertOne(col map[string]any) {
|
||||
func BuildInsertOne(col map[string]any, report *InitReport) {
|
||||
name := col["_name"].(string)
|
||||
singular := col["singular"].(string)
|
||||
|
||||
@@ -39,6 +39,8 @@ func BuildInsertOne(col map[string]any) {
|
||||
isSystem = v.(bool)
|
||||
}
|
||||
|
||||
report.AddField(insertOneName)
|
||||
|
||||
mc := mongo.GetMongoClient()
|
||||
|
||||
// we defer function's implementation until we create the actual struct
|
||||
|
||||
Reference in New Issue
Block a user