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