Skip to content

Commit b4f0fb1

Browse files
author
Derek Dowling
committed
Better parser comments
1 parent a278840 commit b4f0fb1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

parser.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func NewParser(request *http.Request) *Parser {
9494
}
9595

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

114+
// If the document has data, validate against specification
113115
if document.HasData() {
114116
for _, object := range document.Data {
117+
118+
// TODO: currently this doesn't really do any user input
119+
// validation since it is validating against the jsh
120+
// "Object" type. Figure out how to options pass the
121+
// corressponding user object struct in to enable this
122+
// without making the API super clumsy.
115123
inputErr := validateInput(object)
116124
if inputErr != nil {
117125
return nil, inputErr[0]
@@ -128,6 +136,9 @@ func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
128136
return document, nil
129137
}
130138

139+
/*
140+
closeReader is a deferal helper function for closing a reader and logging any errors that might occur after the fact.
141+
*/
131142
func closeReader(reader io.ReadCloser) {
132143
err := reader.Close()
133144
if err != nil {

0 commit comments

Comments
 (0)