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

rql: changing types to pointers #19

Merged
merged 1 commit into from
Aug 1, 2019
Merged
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
12 changes: 6 additions & 6 deletions rql.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ func MustNewParser(c Config) *Parser {
// Parse parses the given buffer into a Param object. It returns an error
// if the JSON is invalid, or its values don't follow the schema of rql.
func (p *Parser) Parse(b []byte) (pr *Params, err error) {
q := new(Query)
q := &Query{}
if err := q.UnmarshalJSON(b); err != nil {
return nil, &ParseError{"decoding buffer to *Query: " + err.Error()}
}
return p.ParseQuery(*q)
return p.ParseQuery(q)
}

// ParseQuery parses the given struct into a Param object. It returns an error
// if one of the query values don't follow the schema of rql.
func (p *Parser) ParseQuery(q Query) (pr *Params, err error) {
func (p *Parser) ParseQuery(q *Query) (pr *Params, err error) {
defer func() {
if e := recover(); e != nil {
perr, ok := e.(ParseError)
perr, ok := e.(*ParseError)
if !ok {
panic(e)
}
Expand Down Expand Up @@ -469,15 +469,15 @@ func (p *Parser) op(op Op) string {
// expect panic if the condition is false.
func expect(cond bool, msg string, args ...interface{}) {
if !cond {
panic(ParseError{fmt.Sprintf(msg, args...)})
panic(&ParseError{fmt.Sprintf(msg, args...)})
}
}

// must panics if the error is not nil.
func must(err error, msg string, args ...interface{}) {
if err != nil {
args = append(args, err)
panic(ParseError{fmt.Sprintf(msg+": %s", args...)})
panic(&ParseError{fmt.Sprintf(msg+": %s", args...)})
}
}

Expand Down