api: use pointers in models to get proper omitempty
semantics
This commit is contained in:
parent
1a5aa88b18
commit
04c7351911
@ -19,8 +19,8 @@ type Error struct {
|
||||
}
|
||||
|
||||
type LayerEnvelope struct {
|
||||
Layer Layer `json:"Layer,omitempty"`
|
||||
Error Error `json:"Error,omitempty"`
|
||||
Layer *Layer `json:"Layer,omitempty"`
|
||||
Error *Error `json:"Error,omitempty"`
|
||||
}
|
||||
|
||||
type Layer struct {
|
||||
@ -63,6 +63,6 @@ type Notification struct {
|
||||
}
|
||||
|
||||
type VulnerabilityWithLayers struct {
|
||||
Vulnerability Vulnerability `json:"Vulnerability,omitempty"`
|
||||
LayersIntroducingVulnerability []string `json:"LayersIntroducingVulnerability,omitempty"`
|
||||
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
|
||||
LayersIntroducingVulnerability []string `json:"LayersIntroducingVulnerability,omitempty"`
|
||||
}
|
||||
|
@ -52,17 +52,17 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx
|
||||
request := LayerEnvelope{}
|
||||
err := decodeJSON(r, &request)
|
||||
if err != nil {
|
||||
writeResponse(w, LayerEnvelope{Error: Error{err.Error()}})
|
||||
writeResponse(w, LayerEnvelope{Error: &Error{err.Error()}})
|
||||
return writeHeader(w, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
err = worker.Process(ctx.Store, request.Layer.Name, request.Layer.ParentName, request.Layer.Path, request.Layer.Format)
|
||||
if err != nil {
|
||||
if _, ok := err.(*cerrors.ErrBadRequest); ok {
|
||||
writeResponse(w, LayerEnvelope{Error: Error{err.Error()}})
|
||||
writeResponse(w, LayerEnvelope{Error: &Error{err.Error()}})
|
||||
return writeHeader(w, http.StatusBadRequest)
|
||||
}
|
||||
writeResponse(w, LayerEnvelope{Error: Error{err.Error()}})
|
||||
writeResponse(w, LayerEnvelope{Error: &Error{err.Error()}})
|
||||
return writeHeader(w, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@ -75,10 +75,10 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
|
||||
|
||||
dbLayer, err := ctx.Store.FindLayer(p.ByName("layerName"), withFeatures, withVulnerabilities)
|
||||
if err == cerrors.ErrNotFound {
|
||||
writeResponse(w, LayerEnvelope{Error: Error{err.Error()}})
|
||||
writeResponse(w, LayerEnvelope{Error: &Error{err.Error()}})
|
||||
return writeHeader(w, http.StatusNotFound)
|
||||
} else if err != nil {
|
||||
writeResponse(w, LayerEnvelope{Error: Error{err.Error()}})
|
||||
writeResponse(w, LayerEnvelope{Error: &Error{err.Error()}})
|
||||
return writeHeader(w, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
|
||||
}
|
||||
|
||||
// add envelope
|
||||
writeResponse(w, LayerEnvelope{Layer: layer})
|
||||
writeResponse(w, LayerEnvelope{Layer: &layer})
|
||||
return writeHeader(w, http.StatusOK)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user