Add error to json response
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
4c24c0f528
commit
a84d3dc9fc
4
main.go
4
main.go
|
@ -33,6 +33,7 @@ var (
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
|
Error error `json:"error,omitempty"`
|
||||||
MatchedRules yara.MatchRules `json:"rules,omitempty"`
|
MatchedRules yara.MatchRules `json:"rules,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +169,7 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.WithField("match", m).Debug("Matched rules")
|
log.WithField("match", m).Debug("Matched rules")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
json.NewEncoder(w).Encode(response{Success: false, Error: err})
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
} else {
|
} else {
|
||||||
json.NewEncoder(w).Encode(response{Success: true, MatchedRules: *m})
|
json.NewEncoder(w).Encode(response{Success: true, MatchedRules: *m})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue