Skip to content

Commit 9555233

Browse files
committed
use decoder
1 parent d3ae2f5 commit 9555233

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

routers/repo/package.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/base64"
99
"encoding/json"
1010
"fmt"
11-
"io/ioutil"
1211
"math/rand"
1312
"net/http"
1413
"regexp"
@@ -328,14 +327,12 @@ func DockerPluginEvent(ctx *context.Context) {
328327
return
329328
}
330329

331-
body, err := ioutil.ReadAll(ctx.Req.Body)
332-
if err != nil {
333-
ctx.Error(http.StatusInternalServerError)
334-
log.Error("Failed to read event: %v", err)
335-
}
330+
decoder := json.NewDecoder(ctx.Req.Body)
331+
decoder.DisallowUnknownFields()
332+
336333
data := new(notifications.Envelope)
337334

338-
err = json.Unmarshal(body, data)
335+
err := decoder.Decode(data)
339336
if err != nil {
340337
ctx.Error(http.StatusInternalServerError)
341338
log.Error("Failed to unmarshal event: %v", err)

0 commit comments

Comments
 (0)