Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ Skip unexported fields as reflection will panic if accessed #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions document_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -113,6 +121,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 {
fieldValue = fieldElem.Elem()
Expand Down