Skip to content

Commit

Permalink
Better parser comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Dowling committed Dec 30, 2015
1 parent a278840 commit b4f0fb1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func NewParser(request *http.Request) *Parser {
}

/*
Document returns a single JSON data object from the parser.
Document returns a single JSON data object from the parser. In the process it will also validate
any data objects against the JSON API.
*/
func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
defer closeReader(payload)
Expand All @@ -110,8 +111,15 @@ func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
return nil, ISE(fmt.Sprintf("Error parsing JSON Document: %s", decodeErr.Error()))
}

// If the document has data, validate against specification
if document.HasData() {
for _, object := range document.Data {

// TODO: currently this doesn't really do any user input
// validation since it is validating against the jsh
// "Object" type. Figure out how to options pass the
// corressponding user object struct in to enable this
// without making the API super clumsy.
inputErr := validateInput(object)
if inputErr != nil {
return nil, inputErr[0]
Expand All @@ -128,6 +136,9 @@ func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
return document, nil
}

/*
closeReader is a deferal helper function for closing a reader and logging any errors that might occur after the fact.
*/
func closeReader(reader io.ReadCloser) {
err := reader.Close()
if err != nil {
Expand Down

0 comments on commit b4f0fb1

Please sign in to comment.