Skip to content

Commit 73dc271

Browse files
authored
Merge pull request #36 from shurcooL/patch-1
Simplify and optimize RemoveMagicPrefixLine.
2 parents 978d5a3 + 09cddf5 commit 73dc271

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

gerrit.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,14 @@ func (c *Client) DeleteRequest(urlStr string, body interface{}) (*Response, erro
436436
//
437437
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
438438
func RemoveMagicPrefixLine(body []byte) []byte {
439-
if bytes.HasPrefix(body, []byte(")]}'\n")) {
440-
index := bytes.IndexByte(body, '\n')
441-
if index > -1 {
442-
// +1 to catch the \n as well
443-
body = body[(index + 1):]
444-
}
439+
if bytes.HasPrefix(body, magicPrefix) {
440+
return body[5:]
445441
}
446442
return body
447443
}
448444

445+
var magicPrefix = []byte(")]}'\n")
446+
449447
// CheckResponse checks the API response for errors, and returns them if present.
450448
// A response is considered an error if it has a status code outside the 200 range.
451449
// API error responses are expected to have no response body.

0 commit comments

Comments
 (0)