Decouple apiserver from codec implementation

The apiserver on initialization must be provided with a codec
for encoding and decoding all handled objects including api.Status
and api.ServerOp.  In addition, the RESTStorage Extract() method
has been changed to New(), which returns a pointer object that the
codec must decode into (the internal object).  Switched registry
methods to use pointers for Create/Update instead of values.
This commit is contained in:
Clayton Coleman
2014-08-05 23:10:48 -04:00
parent 4123a44653
commit c9fc0bcf3d
16 changed files with 140 additions and 128 deletions

View File

@@ -56,7 +56,7 @@ func (s *APIServer) handleOperation(w http.ResponseWriter, req *http.Request) {
if len(parts) == 0 {
// List outstanding operations.
list := s.ops.List()
writeJSON(http.StatusOK, list, w)
writeJSON(http.StatusOK, s.codec, list, w)
return
}
@@ -68,9 +68,9 @@ func (s *APIServer) handleOperation(w http.ResponseWriter, req *http.Request) {
obj, complete := op.StatusOrResult()
if complete {
writeJSON(http.StatusOK, obj, w)
writeJSON(http.StatusOK, s.codec, obj, w)
} else {
writeJSON(http.StatusAccepted, obj, w)
writeJSON(http.StatusAccepted, s.codec, obj, w)
}
}