diff --git a/persist.go b/persist.go index afd811e..2e91d43 100644 --- a/persist.go +++ b/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) diff --git a/persist_deleteone.go b/persist_deleteone.go index bbb4a10..eea5fa8 100644 --- a/persist_deleteone.go +++ b/persist_deleteone.go @@ -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 diff --git a/persist_find.go b/persist_find.go index d2e3311..8a37d08 100644 --- a/persist_find.go +++ b/persist_find.go @@ -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 diff --git a/persist_findone.go b/persist_findone.go index 20662f5..63cbe1f 100644 --- a/persist_findone.go +++ b/persist_findone.go @@ -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 diff --git a/persist_getone.go b/persist_getone.go index 737ee08..0a6f64c 100644 --- a/persist_getone.go +++ b/persist_getone.go @@ -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 diff --git a/persist_insertone.go b/persist_insertone.go index 9700b22..7bce873 100644 --- a/persist_insertone.go +++ b/persist_insertone.go @@ -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