From fa60ab72ceb8c0384301627bbc44611993e6be77 Mon Sep 17 00:00:00 2001 From: Lou-adrien Date: Tue, 9 Jan 2018 13:15:39 +0100 Subject: [PATCH 1/2] + Skip unexported fields as reflection will panic if accessed --- document_base.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/document_base.go b/document_base.go index ad32bc5..72e3e9f 100644 --- a/document_base.go +++ b/document_base.go @@ -112,6 +112,11 @@ func (self *DocumentBase) DefaultValidate() (bool, []error) { fieldName := fieldType.Field(fieldIndex).Name fieldElem := documentValue.Field(fieldIndex) + + // Skip unexported fields as refection will throw a panic if trying to access its value + if field.PkgPath != "" && !field.Anonymous { + continue + } // Get element of field by checking if pointer or copy if fieldElem.Kind() == reflect.Ptr || fieldElem.Kind() == reflect.Interface { From 681bd38ef6ce6740ef1c54c32e43ebc707f9137a Mon Sep 17 00:00:00 2001 From: Lou-adrien Date: Tue, 9 Jan 2018 21:20:49 +0100 Subject: [PATCH 2/2] + added getters --- document_base.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/document_base.go b/document_base.go index 72e3e9f..3774b73 100644 --- a/document_base.go +++ b/document_base.go @@ -29,10 +29,18 @@ type DocumentBase struct { type m map[string]interface{} +func (self *DocumentBase) GetCollection() *mgo.Collection { + return self.collection +} + func (self *DocumentBase) SetCollection(collection *mgo.Collection) { self.collection = collection } +func (self *DocumentBase) GetDocument() IDocumentBase { + return self.document +} + func (self *DocumentBase) SetDocument(document IDocumentBase) { self.document = document } @@ -112,7 +120,7 @@ func (self *DocumentBase) DefaultValidate() (bool, []error) { fieldName := fieldType.Field(fieldIndex).Name fieldElem := documentValue.Field(fieldIndex) - + // Skip unexported fields as refection will throw a panic if trying to access its value if field.PkgPath != "" && !field.Anonymous { continue